Basic operation on char...
-
@njeremy2 said:
Sorry I don't understand the first time I read your post...
I can use attributes but I see in AUTOMATIC Sketchup.pdf that's attributes cannot be stored when you save a component (I understand that)If you store attributes with the definition then you can export the component with the attributes.
Example:
componentinstance.definition.set_attribute('MyTest', 'Foo', 'Bar')
Export component
New model
Import exported model
componentinstance.definition.get_attribute('MyTest', 'Foo')
( returns'Bar'
) -
hmmmm, well...
With that, you can add an attribute called "reference" for all components and set attribute then ?
So if I do like that : componentinstance.definition.set_attribute('Reference', '755480RED', 'Valuedefaultif 755480RED doesnt exist')
That would work ?
And to list all references, how should I do ?
componentinstance.definition.set_attribute('Reference') ? -
Read the API docs again.
set_attribute
takes three arguments. The third one is the value.entity.set_attribute( 'DictionaryName', 'Key', 'Value' )
entity.get_attribute( 'DictionaryName', 'Key' )
So, if you do something like to to add a reference ID:
entity.set_attribute( 'nJeremy2', 'Reference', referenceID )
You can list all definitions with a reference set like so:
<span class="syntaxdefault"><br />for definition in Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definitions<br /> next if definition</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">image</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault"> next if definition</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">group</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault"> referenceID </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> entity</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_attribute</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxstring">'nJeremy2'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'Reference'</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> next if referenceID</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">nil</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Do something to the definition here...<br /></span><span class="syntaxdefault">end<br /></span>
-
yeah ok !
I will try but the result is not guarantee -
my solution by putting the reference in description work, it isn't good programming but it works lol
thank you thom !
-
What if your user accidentally modify the description? Or some other plugin the user has install modifies it?
-
@thomthom said:
What if your user accidentally modify the description? Or some other plugin the user has install modifies it?
right...
But I try to use attributes, but I cannot do it right
-
What is not working right?
Do you have a sample code?When assigning an attribute to the definition the attribute is stored whenever you export - it works fine. But if it doesn't work for you then it's probably something in your code that isn't quite right.
-
@thomthom said:
What is not working right?
Do you have a sample code?When assigning an attribute to the definition the attribute is stored whenever you export - it works fine. But if it doesn't work for you then it's probably something in your code that isn't quite right.
I have nothing at home, tomorrow I'll show you what I need to do with that (with screenshots)
-
For this example I put a tree and a Blue cube.
The tree has no description and the Cube has code reference then the real description after "b755480 BLABLABLA".
Then I create a groupe with the 2 objects called "Tree+cube"Now I export all information with my plugin :
then I export all information in CSV File :
Advertisement