lower case “if” ?
Dam… coming from Rhinoscript it might take awhile to get used to…
Hi @Asterisk, also keep in mind that you must call the methods properly eg:
will just return reference to the function itself and does nothing without parenthesis. It should be like below instead:
Is this the same?
Is there more elegant way of orienting CPlane perp to curve in default position
In this case yes.
vb Rhinoscript and Python rhinoscriptsyntax do differ on how they approach supplying arguments to methods.
in vb, if you have several arguments, and you are not going to specify them all, you can just leave a space like this
Here, I skipped the object filter and the group arguments, but specified “preselect” to be True
In python, that is not allowed. However, you can skip arguments by discreetly (specifically) naming those that come after (otherwise known as “keyword arguments”):
Which does the same thing as the vb version above.
One other thing to know about this is that arguments still have to be in the correct order, and that you cannot use a non-specified argument in a position after one in which you have specified an argument name.
rs.GetObjects("message", preselect=True, select=False) is OK.
rs.GetObjects("message", preselect=True, False) is not.
In the case of your rs.Command() there are only two arguments to specify, the command string itself and whether you want to echo or not, so assuming you always specify a command string as the first argument, you can either use the keyword or not for the second.
Thank God! is rs.DimScale() = Rhino.DimStyleScale?
Well, you could use native rhinoscriptsyntax methods - it also depends if you want to actually set the CPlane in the viewport, or if you just need a plane perpendicular to the curve at some point to do some other stuff which does not require user interaction. In the second case, I would calculate the plane without changing the CPlane in the viewport (less invasive).
You will need to know a little about how planes are handled perhaps. Here is a code snippet for setting the active viewport’s CPlane to the midpoint of the selected curve.
import rhinoscriptsyntax as rs crv=rs.GetObject("Select a curve",4) if crv: mp=rs.CurveMidPoint(crv) param=rs.CurveClosestPoint(crv,mp) frame=rs.CurvePerpFrame(crv,param) #frame will be a plane perpendicular to the curve at the midpoint #set the current viewport CPlane to the frame plane: rs.ViewCPlane(rs.CurrentView(),frame)
^ Thanks that’s exactly what I needed. I need to print out all the rs methods and read what they do. CurvePerpFrame is what I was missing.
Not sure… DimStyleScale does not exist in python rhinoscriptsyntax, and DimScale does not exist in vb rhinoscript… nor does it seem to exist in V6 rhinoscriptsyntax, only V5… So not sure what to tell you here.
I’m still on R5 for a time being. So how do I get a current dim style scale in python? I use it to “scale” the text that script would add to the document.
Also, is rs.LastCreatedObjects() = Rhino.LastCreatedObects(0)?
In V5, this doesn’t seem possible via python, the method is not exposed in RhinoCommon. It is in V6.
Yes. Just beware that with either language, if no “last objects” have been created, the script will error out - because you are trying to get an item from an array/list that doesn’t exist. Better is to do this:
lco=rs.LastCreatedObjects() if lco: obj=lco
Maybe using the scripted command
_ScaleDimstyle to increase the size in V5 ?
Hmm, thanks for pointing out that command Clement, don’t think I ever used it - it doesn’t exist anymore in V6 looks like.
Hi Mitch, i did not notice that it’s gone in V6.
Maybe if @Asterisk only requires to scale the Text, he could also use the
TextHeight property of the dimension style. Eg like this in python, this makes the change on the current dimension style, tested in V5 only.
import scriptcontext dim_style = scriptcontext.doc.DimStyles.CurrentDimensionStyle dim_style.TextHeight = 2.0 dim_style.CommitChanges() scriptcontext.doc.Views.Redraw()
it is the same as
or use this to control the text size when adding it.
The problem with that is that it’s the same (0.1) for all our dim styles and only Model space scale number change.
So the workaround is kinda ugly, but acceptable - pull a leader in a dim style I need (current), explode it and clean up leftover curves. Then I can read the text height, 'cause it’ll be 0.1 multiplied by w/e current dim style scale is. I see even R5 python doesn’t have masking and mask margin exposed, so I’m forced to use -Text command to get masked text created.
Any idea on why text object text isn’t being “processed” or how to “process” it so it shows what it’s supposed to show without manually double clicking the text and escaping out of it?
import rhinoscriptsyntax as rs
OX = rs.ViewCPlane()
CL = rs.CurrentLayer()
if not rs.IsLayer(“DIMs::SysDepths”):
rs.AddLayer(“DIMs::SysDepths”, (250, 0, 0))
if (CL.find(“SysDepths”) == -1):
print “Draw a system depth line FROM PANEL FACE back to substrate.”
SDL = rs.LastCreatedObjects()
if (SDL): SDL=SDL else: break #rs.EnableRedraw(False) rs.ObjectPrintWidth(SDL,-1) rs.ObjectColor(SDL,(105,0,0)) rs.ReverseCurve(SDL) rs.UnselectAllObjects() rs.SelectObject(SDL) rs.Command("_CPlane C _Enter",False) rs.Command("_Dimcurvelength 1,2,0 2,2,0 _Enter",False) rs.UnselectAllObjects() rs.SelectObject (rs.FirstObject()) rs.Command("_Explode",False) tmpLdr = rs.LastCreatedObjects() for x in range(0,len(tmpLdr)): if rs.IsText(tmpLdr[x]): txHt = rs.TextObjectHeight(tmpLdr[x]) rs.DeleteObjects(tmpLdr) rs.Command("-Text 2,2,0.5 F " + chr(34) + "Times New Roman" + chr(34) + " H " + str(txHt) + " Mask=Yes UseBackgroundColor=No MaskColor=255,255,255 MaskMargin=.1 xYz",False) lbl = rs.FirstObject() rs.MoveObject(lbl, rs.CurveEndPoint(SDL)-rs.CurveStartPoint(SDL)) rs.TextObjectText(lbl,"%<curvelength(" + chr(34) + str(SDL) + chr(34) + ")>%") rs.TextObjectStyle(lbl,1) rs.AddObjectsToGroup((SDL,lbl),rs.AddGroup()) rs.ViewCPlane(None,OX) #rs.EnableRedraw(True)
This works perfectly in any view other than true plan view (top down onto CPlane). Why? Why does it matter? I’ve not had this issue with Rhinoscript scripts.
It will fail if I disable Redraw and it will fail if I’m in a true top down view (all tested views are parallel projection if that matters).
So, I figured why the script fails with redraw off or in plan view where leader that’s getting exploded is not visible - rs.Command(“Explode”) on a leader does not create a text that normally happens when exploding leaders straight in Rhino…
And changing rs.Command("_Dimcurvelength 1,2,0 2,2,0 _Enter",False) to rs.AddLeader(([0,0,0],[1,0,0]),None,“xYz”) forces rs.Cmnd(“Explode”) to create a text… I guess python doesn’t like text fields…
That also fixed the issue with disabling redraw…
And changing this
rs.TextObjectText(lbl,"%<curvelength(" + chr(34) + str(SDL) + chr(34) + “)>%”)
tmp = rs.coercerhinoobject(lbl, True, True) tmp.Geometry.TextFormula = "%<curvelength(" + chr(34) + str(SDL) + chr(34) + ")>%" tmp.CommitChanges()
fixed the text field/formula issue. I just have no idea what the hell it’s doing 'cause there’s no doc on it that I could find in Rhino.
The documentation for rhinoscriptsyntax is online. Also partly visible through the rhino Python editor.
However by coercing a Rhino object you have crossed the boundary into RhinoCommon