algorithmic modeling for Rhino
I have a Rhino file with wireframe. Some of the wires have ObjectNames and some don't. I need to udpate ObjectName based from an existing list.
For this:
1) Using one GH-solution I got the GUID and the ObjectName of a selected set of objects from a Rhino model in CSV format.
2) Opened this in Excel, Column-A contains the GUID, Column-B contains ObjectNames.
3) Modified and revised the ObjectNames in Excel.
4) Using another GH-solution, Wrote a VB script to push this modified data back into the model. However after baking, the objectName is not getting updated.
Though the solutions do not show any runtime errors, after baking, the ObjectNames are not updated. However, if I try selecting the object using:
obj.Select < - this gives an error
--------------------------------------------------------
Here is the code to my GH-solution (see attached image)
WriteToXL module:
------------------------------------------------------------------------------
Private Sub RunScript(ByVal id As Object, ByRef mName As Object, ByRef GUID As Object, ByRef A As Object)
Dim obj As Rhino.DocObjects.RhinoObject = doc.Objects.Find(id)
'Dim A As String
Dim mP1(2) As Double
Dim mP2(2) As Double
Dim mCurve As Rhino.DocObjects.CurveObject
If obj Is Nothing Then
mName = "Obj not found"
Else
If obj.ObjectType = Rhino.DocObjects.ObjectType.Curve Then
mCurve = obj
mP1(0) = mcurve.CurveGeometry.PointAtStart.X
mP1(1) = mcurve.CurveGeometry.PointAtStart.Y
mP1(2) = mcurve.CurveGeometry.PointAtStart.Z
mp2(0) = mcurve.CurveGeometry.PointAtEnd.X
mp2(1) = mcurve.CurveGeometry.PointAtEnd.Y
mp2(2) = mcurve.CurveGeometry.PointAtEnd.Z
End If
mName = CType(obj.Name, String)
GUID = obj.id
A = GUID.ToString & ", " & CStr(mName) & ", " & mp1(0) & ", " & mp1(1) & ", " & mp1(2) & ", " & mp2(0) & ", " & mp2(1) & ", " & mp2(2)
End If
End Sub
-------------------------------------------------------
ReadFromXL module:
-------------------------------------------------------
Private Sub RunScript(ByVal activate As Object, ByRef A As Object, ByRef B As Object, ByRef C As Object)
If activate = True Then
Dim XLApp As Object
Dim XLSheet As Object
xlApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application")
Dim strSheet As String = "ObjectName+GUID"
XLSheet = xlApp.Worksheets(strSheet)
Dim strGUIDColumn As String = "A"
Dim strObjectNameColumn As String = "L"
Dim iRow As Int16
Dim nRows As Int16 = XLSheet.usedrange.rows.count
Dim obj As Rhino.DocObjects.RhinoObject
ReDim B(nRows - 1)
ReDim C(nRows - 1)
ReDim A(nRows - 1)
For iRow = 1 To nRows
Dim strGUID As String = XLSheet.Range(strGUIDColumn & iRow).Value
Dim objGUID As Guid = New System.Guid(strGUID)
Dim strObjectName As String = XLSheet.Range(strObjectNameColumn & iRow).Value
obj = doc.Objects.Find(objGUID)
obj.Attributes.Name = strObjectName
B(iRow - 1) = objGUID
C(iRow - 1) = obj.Attributes.Name
A(iRow - 1) = obj
Next
End If
End Sub
----------------------------------------------------------------
Tags:
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by