Collecting 2D Points

Collecting 2D Points

J-Camper
Advisor Advisor
531 Views
2 Replies
Message 1 of 3

Collecting 2D Points

J-Camper
Advisor
Advisor

I am trying to write some code that examines each vertex of a solid and filters out all vertices that are not on the XY Plane.  I'm having trouble storing the "good" vertices for later use.

 

Sub AnalyzeSolid()

Dim oVertex As Vertex
Dim logVertices() As Point2d
Dim vCount As Integer
vCount = 0
'Filter out all except Z=0 points
For Each oVertex In oSolid.Vertices()
	If oVertex.Point.Z = 0 
		logVertices(vCount)= oTG.CreatePoint2d(oVertex.Point.X,oVertex.Point.Y)
		vCount = (vCount + 1)
	End If
Next

End Sub

My "storage" object [logVertices] is not referenced correctly, and gives error: "Object reference not set to an instance of an object."  I don't know what I should be using to collect a batch of 2D Points.  Any help would be appreciated.

0 Likes
Accepted solutions (1)
532 Views
2 Replies
Replies (2)
Message 2 of 3

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, could you be useful to create a collection of 2d points as below? Regards!

 

doc = ThisDoc.Document
CD = doc.componentdefinition
oSolid = CD.Surfacebodies.Item(1)
oTG =  ThisApplication.TransientGeometry

Dim oVertex As Vertex
Dim oBjCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
'Filter out all except Z=0 points
For Each oVertex In oSolid.Vertices()
	If oVertex.Point.Z = 0 
		Dim oPoint As Point2d = oTG.CreatePoint2d(oVertex.Point.X, oVertex.Point.Y)	
		oBjCol.Add(oPoint)
	End If
Next


For i As Integer = 1 To oBjCol.Count
MessageBox.Show("Point_" & i & " | " &  "X: " & oBjCol(i).X &  " | Y: " & oBjCol(i).Y)
Next

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 3 of 3

J-Camper
Advisor
Advisor

Thank you for that, ObjectCollection was what I needed; although, I was also having trouble declaring the transient geometry object in a Class above my subs.  This post was about a small sub function in a Class and I was hoping to declare Transient Geometry once as a shared object, but it didn't like your solution until I moved the declaration of Transient Geometry into the Sub Function.  This just means making a new transient geometry object in each sub function, unless I can find a way to share it. 

 

Also, I tried multiple routes before posting my code here and my original plan was to log edges as lines.  I'm thinking the Object Collection should be able to do that as well?  Just thinking out loud here, I will try it myself.

 

Thanks again for your help.

0 Likes