I am writing a Rhino script to export the selected Objects into a DXF file. As each object in the 3dm has a name nearby. So during the selection, I am selecting all the curves + the name.
For example:
I have started a script like this, but the problem is I do not want to loop through all the selected objects to find the text. Is there a fast way to get the Text string out from the selection?
Sub SmartSelectionExport()
Dim arrObjects
Dim strObject
Dim strFileName
Dim strPathName
Dim strAnnotation
arrObjects = Rhino.GetObjects("Select objects for export as .DXF", 4 + 512, True, True, True)
If IsArray(arrObjects) Then
For Each strObject In arrObjects
If Rhino.IsText(strObject) Then
strFileName = Rhino.TextObjectText(strObject) + ".dxf"
End If
Next
If IsNull(strFileName) Then
Exit Sub
End If
strPathName = Rhino.DocumentPath() + "\" + strFileName
' runs the export using the file name/path and your settings
Call Rhino.Command("-_Export " & chr(34) & strPathName & chr(34) & " Scheme Default Enter", True)
End If
End Sub
Also, I do not want to have to press Enter to finish the selection. Is there a way to disable that?
This is probably not the best way to do it but it works. Using the code attached, you need to pick the text wanted for the name as the first pick of the selection:
arrObjects = Rhino.GetObjects("Select objects for export as .DXF", 4 + 512, True, True, True)
If IsArray(arrObjects) Then
strObject = arrObjects(0)
If Rhino.IsText(strObject) Then
strFileName = Rhino.TextObjectText(strObject) + ".dxf"
Else
Rhino.Print "First Picked item is not text"
Exit Sub
End If
End If
If not IsNull(strFileName)Then
strPathName = Rhino.DocumentPath() + ââ + strFileName
' runs the export using the file name/path and your settings
Call Rhino.Command("-_Export " & chr(34) & strPathName & chr(34) & " Scheme Default Enter", True)
End If
Rhino.UnSelectAllObjects
Havenât figured out how to grey out the code yetâŚ
If the name chosen for the dxf already exists in the folder, then that existing file will be over-written
Take care using the âDefaultâ export scheme as it will explode all your polylines, your black lines will remain black at the recipient end, tricky if they have a black backfround, your layer names are full path which can be really messy for the recipient and âchord heightâ is un-checked, so there is a good chance your polylines will lose accuracy which could go un-noticed until assembly time. It would be safer to experiment and create a custom scheme to suit your needs.
1 Like