Ilogic Point Pattern

Ilogic Point Pattern

uo9K5H5
Contributor Contributor
782 Views
5 Replies
Message 1 of 6

Ilogic Point Pattern

uo9K5H5
Contributor
Contributor

Hello,

I am working on a iLogic rule that put a point pattern on a sketch driven path. I have manage to find some program that is able to make a quick sketch with path I need. But I would really appreciate if someone can help me how to use made path for point pattern with origin at the start of the  sketched path. I am attaching photo and code for better perception. 

'  a reference to the currently active document.
' This assumes that it is a part document.
Dim oPart As PartDocument
oPart = ThisApplication.ActiveDocument

'  a reference to the component definition.
Dim oDef As PartComponentDefinition
oDef = oPart.ComponentDefinition

Dim oSketch As PlanarSketch
oSketch = oDef.Sketches.Add(ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select Face to Place Sketch"))

sketchName = InputBox("Give your new sketch a name", "Sketch Name", "Enter Sketch Name Here")
oSketch.Name = sketchName
oSketch.Edit

Dim edges As ObjectCollection  
Dim edge As Edge 

edges = ThisApplication.TransientObjects.CreateObjectCollection

While True
	edge = ThisApplication.CommandManager.Pick(
		SelectionFilterEnum.kPartEdgeFilter, 
		"Select a edge") 
		
	' If nothing gets selected then we're done	
	If IsNothing(edge) Then Exit While
	
	edges.Add(edge) 
End While

' If there are selected components we can do something
For Each edge In edges
	Call oSketch.AddByProjectingEntity(edge)
Next

oSketch.ExitEditPot.png
0 Likes
783 Views
5 Replies
Replies (5)
Message 2 of 6

uo9K5H5
Contributor
Contributor

All I have managed to found out is how to save sketch without renameing it manually.  I know that there must be a solution with adding a work point in the starting point of the edge path and then patterning these work point across the edges. I would appreciate some help 🙂

 

'  a reference to the currently active document.
' This assumes that it is a part document.
Dim oPart As PartDocument
oPart = ThisApplication.ActiveDocument

'  a reference to the component definition.
Dim oDef As PartComponentDefinition
oDef = oPart.ComponentDefinition

Dim oSketch As PlanarSketch
Dim oSketchNameSuffix As Integer
Dim oNameCompare As String
Dim oNameNumCount As Integer
Dim oNameCharCount As Integer

If oHoleType = "Thru" Then
	oSketchNameSuffix = 0
	oNameCompare = "SK_Hole_"
	oNameCharCount = 8
	oNameNumCount = 9

Else If oHoleType = "Pilot" Then
	oSketchNameSuffix = 0
	oNameCompare = "SK_Pilot_"
	oNameCharCount = 9
	oNameNumCount = 10

End If

'Check all sketches in the model tree and compare the names to the
'name of the newly created sketch and if name exists increment the
'suffix by 1. Continue until the newly created sketch name is unique
'and can be used.
On Error Resume Next
	For Each oSketchNameCheck As Sketch In oDef.Sketches
		If Left(oSketchNameCheck.Name,oNameCharCount) = oNameCompare Then
			Dim oSketchNumber As Integer = Val(Mid(oSketchNameCheck.Name, oNameNumCount, 2))			
	        While oSketchNameSuffix <= oSketchNumber
				oSketchNameSuffix = oSketchNameSuffix + 1
			End While
		End If	
	Next 
	
oSketch.Name = oNameCompare & oSketchNameSuffix


oSketch = oDef.Sketches.Add(ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select Face to Place Sketch"))

Dim edges As ObjectCollection  
Dim edge As Edge 

oSketch = oDef.Sketches.Add(OFace, False)
oSketch.AxisEntity = FrontEdge
oSketch.OriginPoint = FrontEdge.StartVertex
oSketch.NaturalAxisDirection = True

edges = ThisApplication.TransientObjects.CreateObjectCollection

While True
	edge = ThisApplication.CommandManager.Pick(
		SelectionFilterEnum.kPartEdgeFilter, 
		"Select a edge") 

	' If nothing gets selected then we're done	
	If IsNothing(edge) Then Exit While	
	edges.Add(edge) 
	
End While

' If there are selected components we can do something
For Each edge In edges
	Call oSketch.AddByProjectingEntity(edge)
Next

oSketch.ExitEdit


 

0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor

This seems like it might be a little to custom and complex for someone remote to create a solution for, without a test files to work with, and perhaps a little clearer goals.  The picture pasted in your original post has a lot of green geometry in it, but one shorter series of yellow lines, that looks like you maybe have some edges selected or sketch geometry following some edges.  Do you want code that will create a sketch point object at each end and intersection of all geometry shown in that image, or just the yellow geometry, or is neither of these assumptions right?  It seems like your code is attempting to create new sketch geometry by projecting all model geometry edges that you select.  Are all of these selected pieces of geometry, when they become sketch geometry, going to be connected in a series of lines, arcs, splines, etc.?  Do these point objects need to be created as regular dot type points or as circle center point type points.  I'm assuming that since your second code involved terms for holes, that you want them to be center point type points, because you are planning on using them for hole feature center points.

 

Can you maybe attach a sample file for us to test with, and maybe a bullet point list of things you want to have happen as the code progresses (in order)?  If you do post an Inventor file, make sure it doesn't contain any proprietary or private information you wouldn't want others to see.  And specify which version of Inventor it was last saved in, for compatibility reasons.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 6

uo9K5H5
Contributor
Contributor

Maybe the post is really poorly written. The entire green geometry in the picture represents the path of the cable tray. My goal is to divide the entire geometry into several smaller 3000 mm long segments. I am going to use Frame Insert feature to insert 3000 mm long frames. Frame Insert can not insert custom length profiles, but It can just make the profile through the entire selected edge or between two points. So that is why I need work points to be patterned across the edge. The wish is for the program to work in the following order:

1.  Run the rule

2.  Select a face for sketch and all the edges which are automatically saved in a sketch with a unique name

3.  First work point to be placed on the starting end of sketched edges

4.  All the rest work points patterned across the made path. The number of the work points should be as many as are needed to come across the whole path.


I am also attaching a test file.

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

There were numerous coding issues going on within the sketch renaming section of the code, so I only dabbled with that section a little bit, then commended it out entirely for now. For one thing, you can't check the value of a variable, if that variable hasn't been created yet, and has not been given a value yet.  This was the case with the 'oHoleType' variable, and the 'FrontEdge' variable.  Then it looks like you tried to assign a name to the 'oSketch' variable before you have given 'oSketch' a value (it wasn't pointing to a specific sketch object yet).  I don't know if that line was intended to be within the loop above, or after the lines below, where we create the new sketch object.

 

Then I focused on the main function of the rule, which was to allow you to select edges, create projected sketch geometry from those edges, then create work points at the end points of each projected sketch geometry, so you can use the resulting work points to generate new sections of model geometry.  I believe I have this main part of the code working for you as intended.

Dim oPart As PartDocument = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition = oPart.ComponentDefinition
'[
'Dim oSketchNameSuffix As Integer
'Dim oNameCompare As String
'Dim oNameNumCount As Integer
'Dim oNameCharCount As Integer

''the variable oHoleType was not defined yet, so none of the related code was working
'Dim oHoleTypes As New List(Of String) From {"Thru", "Pilot"}
'Dim oHoleType As String = InputListBox("", oHoleTypes, "Thru", "Hole Types", "Hole Types List")
'If String.IsNullOrEmpty(oHoleType) Then
'	Exit Sub
'ElseIf oHoleType = "Thru" Then
'	oSketchNameSuffix = 0
'	oNameCompare = "SK_Hole_"
'	oNameCharCount = 8
'	oNameNumCount = 9
'ElseIf oHoleType = "Pilot" Then
'	oSketchNameSuffix = 0
'	oNameCompare = "SK_Pilot_"
'	oNameCharCount = 9
'	oNameNumCount = 10
'End If

''Check all sketches in the model tree and compare the names to the
''name of the newly created sketch and if name exists increment the
''suffix by 1. Continue until the newly created sketch name is unique
''and can be used.
'On Error Resume Next
'	For Each oSketchNameCheck As Sketch In oDef.Sketches
'		If Left(oSketchNameCheck.Name,oNameCharCount) = oNameCompare Then
'			Dim oSketchNumber As Integer = Val(Mid(oSketchNameCheck.Name, oNameNumCount, 2))			
'	        While oSketchNameSuffix <= oSketchNumber
'				oSketchNameSuffix = oSketchNameSuffix + 1
'			End While
'		End If	
'	Next 
''you haven't given the variable oSketch a value yet,
''so it doesn't know which sketch you are talking about,
''so it isn't doing anything here
'oSketch.Name = oNameCompare & oSketchNameSuffix
']

Dim oFace As Inventor.Face
SelectFace :
oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select Face to Place Sketch")
If oFace Is Nothing Then
	MsgBox("No face was selected. Exiting.",,"")
	Exit Sub
ElseIf oFace.SurfaceType <> SurfaceTypeEnum.kPlaneSurface Then
	MsgBox("Selected face was not planar. Please select planar (flat) face.", , "")
	GoTo SelectFace
End If

Dim oSketch As PlanarSketch = oDef.Sketches.Add(oFace, False)
'the variable FrontEdge has not been created or a value given to it yet, so the following 2 lines will do nothing
'oSketch.AxisEntity = FrontEdge
'oSketch.OriginPoint = FrontEdge.StartVertex
'oSketch.NaturalAxisDirection = True
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim oEdges As ObjectCollection = oTO.CreateObjectCollection
Dim oPoints As ObjectCollection = oTO.CreateObjectCollection
Dim oEdge As Edge
Dim oPoint As Inventor.Point

Do
	oEdge = ThisApplication.CommandManager.Pick( _ 
	SelectionFilterEnum.kPartEdgeFilter, "Select a edge") 
	' If nothing gets selected then we're done
	If oEdge IsNot Nothing Then
		oEdges.Add(oEdge)
	Else
		Exit Do
	End If
	Dim oSE As SketchEntity = oSketch.AddByProjectingEntity(oEdge)
	If TypeOf oSE Is SketchLine Then
		Dim oSL As SketchLine = oSE
		oPoints.Add(oSL.StartSketchPoint.Geometry3d)
		oPoints.Add(oSL.EndSketchPoint.Geometry3d)
	ElseIf TypeOf oSE Is SketchArc Then
		Dim oSA As SketchArc = oSE
		oPoints.Add(oSA.StartSketchPoint.Geometry3d)
		oPoints.Add(oSA.EndSketchPoint.Geometry3d)
	End If
	MsgBox("oEdges.Count = " & oEdges.Count & vbCrLf & _
	"oPoints.Count = " & oPoints.Count,,"")
Loop Until oEdge Is Nothing
'oSketch.ExitEdit 'don't need this because we never entered interactive Edit mode
'oSketch.Visible = False
'or
'oSketch.Delete

For Each oPoint In oPoints
	Dim oDuplicate As Boolean = False
	Dim oWP As WorkPoint = Nothing
	For Each oWP In oDef.WorkPoints
		If oWP.Point.X = oPoint.X And _
			oWP.Point.Y = oPoint.Y And _
			oWP.Point.Z = oPoint.Z Then
			oDuplicate = True
		End If
	Next
	If oDuplicate = False Then
		oWP = oDef.WorkPoints.AddFixed(oPoint, False)
	End If
Next

However, it seems like a very inefficient process to go through, if all you really need is the set of work points.  Since this process already includes a bunch of manual user interactions (mouse selections), why not just skip creating a sketch and directly select the vertexes to be used as work point location?

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 6

uo9K5H5
Contributor
Contributor

@WCrihfield The program that you have helped me, suits me well. (Thank you) But I would like to achieve one more thing. I would like to have all the linear edges with starting and ending point (which is already done - PERFECT!) and on the edges that are longer then 3000 mm pattern of the working points on every 3000 mm. If we end up with a residue smaller than 3000 mm it doesn’t bother me. The parts that are smaller then 3000 mm we leave with only starting and ending points. Is these possible to achieve? Can you help me with writing down the code?