Hello,
I need to create a python script that will make block definition with block attributes.
Then, (from the same script) I want to add (multiple) instances of that block and each time to assign arbitrary attribute values
Thanks in advance
Aleksandar
dale
(Dale Fugier)
August 12, 2021, 7:23pm
2
Hi @AleksandarSM ,
Here is something pretty basic:
import Rhino
import scriptcontext as sc
def test_kitchen_sink():
origin = Rhino.Geometry.Point3d.Origin
plane = Rhino.Geometry.Plane.WorldXY
geometry = []
circle = Rhino.Geometry.Circle(plane, 10.0)
curve = Rhino.Geometry.ArcCurve(circle)
geometry.append(curve)
str = '%<UserText("block","Sink","Manufacturer","Kohler")>%'
style = sc.doc.DimStyles.Current
text = Rhino.Geometry.TextEntity.Create(str, plane, style, False, 0.0, 0.0)
text.Justification = Rhino.Geometry.TextJustification.MiddleCenter
geometry.append(text)
idef_index = sc.doc.InstanceDefinitions.Add("Sink", "Kitchen Sink", origin, geometry)
if __name__=="__main__":
test_kitchen_sink()
From here, just script the _-Insert
command.
– Dale
1 Like
A="MyProd"
myCommand = " ! _-Insert " + "Sink" + " _Enter " + A + " 100,100,100 1 0 "
rs.Command(myCommand)
it works. Thanks!
in case someone else needs a block with multiple attributes:
Define multiple attributes as in Dale's post above:
str1 = '%<UserText("block","Att1","Manufacturer","Kohler")>%'
str2 = '%<UserText("block","Att2","Size","10")>%'
str3 = '%<UserText("block","Att3","Color","White")>%'
...............
then insert block with all attributes assigned
A="MyProd"
B="12"
C="Blue"
myCommand = " ! _-Insert " + "Sink" + " _Enter " + A + " " + B + " " + C + " 100,100,100 1 0 "
rs.Command(myCommand)
BR