Continuing the discussion from Is this the best way to automatically update linked blocks?:
Hi Jorgen,
Below a description on how I find my way in RhinoCommon through Python:
starting with the code:
import rhinoscriptsyntax as rs
blockList=rs.BlockNames()
I put a debug breakpoint at the last line:
Run the code with the green arrow (F5).
The script stops at line 2 and you get options to continue, StepInto SetOver over …etc
Choose StepInto
The script will step into the code rs.BlockNames() and the containing scriptfile is opened in a new tab:
You see what rs.BlockNames() does and how it interacts with scriptcontext.
scriptcontext is the context where this script is running in thus the current active file.
It’s a means to read information from the current file.
As you can see below scriptcontext.doc is referencing Rhino.DocObjects for the current file.
Now keep stepping until you reach line 172:
In the list at the bottom we see what our different variables are.
Notice how scriptcontext.doc.InstanceDefinitions.Getlist(True) looks like a method. That is passed the argument ‘True’ it returns a list of instance definitions:
If we dig into the list we find single objects identifying the blocks in our file:
Back to the rest of the script:
We Step Into the method rs.BlockStatus()
Notice how again first the scriptcontext.doc.InstanceDefinitions
is used to find the block by it’s name.
In line 218 for the instance definition the property ArchiveFileStatus is converted into an integer.
Lets find out what this is about.
I copy ArchiveFileStatus
and search for it on this page:
http://developer.rhino3d.com/api/RhinoCommon/html/N_Rhino.htm#!
To find this:
To get the status of my blocks I can now do this:
import scriptcontext
for idef in scriptcontext.doc.InstanceDefinitions :
status=int(idef.ArchiveFileStatus)
print status
Now for another approach to find out if there is a way in RhinoCommon to update a block definition.
On the left tree view of the scripteditor I browse for InstanceDefinition
The object type has both methods and properties.
A property is retrieved like so:
InstanceDefinition.Index
Whereas a Methods ends with parantheses with or without arguments
InstanceDefinition.GetObjects()
If you click a property or method you get some info in the console:
We were looking for a way to update and apparently there is no way to update an instancedefinition by itself.
I revert to browsing the tree yet now for the InstanceDefinitionTable
There I find a method to Update a definition. I see a list of what arguments this method needs.
After some trial and error and looking up more info on the InstanceDefinitionTable here:
http://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_DocObjects_Tables_InstanceDefinitionTable.htm
I got the script I posted in the original topic.
HTH
-Willem