Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

ilogic to project sketch entities of a feature

They_Call_Me_Jake
Advocate

ilogic to project sketch entities of a feature

They_Call_Me_Jake
Advocate
Advocate

I am wanting to use iLogic to create a new sketch in a part and and project the sketch entities of a feature into this new sketch. For example, say I had a part that had a pattern of holes, I want to create a new sketch and project all of the hole edges to this new sketch. I have figured out how to create, name and edit a new sketch but I have only found how to pick an edge to project into this new sketch. What I would like is to be able to reference a feature like a pattern and have the ilogic go thru and project all of the entities from that pattern so if there where 10 holes it would project 10 circles and then if the pattern quantity was either increased or decreased I could run the code again and it would project the new number of circles from the pattern. I'm not a programmer so I fumble thru putting code together to do what I want but I can't seem to find anything about how to project entities from a feature. Can anyone let me know if what I am wanting to do is possible and if so maybe help me with the code. Here is what I have so far.

'  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
oSketch.AddByProjectingEntity(ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select Edges"))

TIA

0 Likes
Reply
Accepted solutions (1)
3,592 Views
9 Replies
Replies (9)

chandra.shekar.g
Autodesk Support
Autodesk Support

@They_Call_Me_Jake,

 

Try below iLogic code to project entities to new sketch. After selection of edges, press "Esc" key to complete edge selection.

'  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.ExitEdit

Please feel free to contact if there is any queries.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes

They_Call_Me_Jake
Advocate
Advocate
Thank you for the reply. I was looking for more of an automated approach where user input was not needed. For example in the iLogic code specify which feature (by name) I want to be able to project the edges from and then just have it do a for loop thru and collect all the edges of that feature whether it is a hole, extrude cut or pattern of holes. I was able to project the edges of an extrude if it didn't go completely thru the main body because I could just select the face at the bottom of the extrude cut, where I am have difficulty is when the hole or extrude cut go completely thru the main body then the is no bottom face to pick.
0 Likes

dgreatice
Collaborator
Collaborator

Hi,

 

Can you use Autoproject edges for sketch creation and edit in Application Options?

 

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes

dgreatice
Collaborator
Collaborator

can you provide video, how you use projection geometry and add geometry in manually process?

 

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes

They_Call_Me_Jake
Advocate
Advocate

@dgreatice The autoproject edges won't work for what I'm trying to accomplish. I'll try to explain our process. All of our designing is done in Inventor. After the design is done we save all of the parts as 2D DXF files to prepare for cutting on a CNC Router. We use a program called RouterCIM which uses layers from AutoCAD to determine what bit to use as well as speeds, feeds and machining type such as pocket, mill or outside cuts. All of our layers are set up with a description and then a number to make each layer name unique. We have a sketch for each type of operation, for example the outside shape would be in its own sketch and say a pattern of holes would have their own sketch. I have ilogic code that when a part is placed in a drawing it finds all the sketches that have the layer numbers in the name and assigns the proper layer to each sketch. We can't use autoproject when we create a new sketch because then the lines for the outside shape would be in the same sketch as any other geometry like holes which would get a different layer for drilling. Right now we can use some of the sketches used to create the solids or cuts and just name them accordingly but if we have a pattern of holes that changes from part to part there is no sketch except the parent. We thought we could just create a separate sketch that produced the same spacing as the pattern itself but Inventor has a problem with this when you make a sizable change to the base part sometimes dimensions in a sketch without a feature will flip and the sketch representing the hole pattern will be in the opposite direction as the actual pattern of holes. Another area that is a problem is say we have a tab in one part and need to remove material from another part that the tab goes into we do a "Copy and Combine" to remove that material but since there is no sketch there is nothing for my code to look for to apply the correct layer. I'm not sure that what I'm trying to accomplish here will resolve that last issue but one step at a time. I hope this explains a little better what I'm trying to accomplish.     

0 Likes

They_Call_Me_Jake
Advocate
Advocate

@dgreatice wrote:

can you provide video, how you use projection geometry and add geometry in manually process?

 

 


@dgreatice Not sure what the purpose is of a video showing how I manually project and how I use it. All of the parts we model are flat parts and if there is a pattern of holes in a part that I need an actual sketch for, I create a sketch and project each hole. Or if it is something I will use multiple times then I will create a sketch and then draw a circle and dimension it so I can create a sketch pattern that matches the hole pattern I created earlier. In any event I am trying to make an automated process that will allow me to reference the feature in iLogic whether it is a shape or a pattern and have the code create the sketch and project the edges of the shape or pattern into the sketch which I use later in a drawing


 



0 Likes

They_Call_Me_Jake
Advocate
Advocate

Just a bump to see if there is anyone that can help me out on this.. Not sure if what I'm wanting to do is even possible but if so I could use some help figuring out how to accomplish it.

0 Likes

BrianEkins
Mentor
Mentor
Accepted solution

I think this might give you what you need.  I quickly prototyped it in VBA but it can easily be converted to be VB.NET compatible, which is what iLogic uses.

 

Public Sub AutoProject()
    '  a reference to the currently active document.
    ' This assumes that it is a part document.
    Dim oPart As PartDocument
    Set oPart = ThisApplication.ActiveDocument
    
    '  a reference to the component definition.
    Dim oDef As PartComponentDefinition
    Set oDef = oPart.ComponentDefinition
    
    Dim planeEnt As Object
    Set planeEnt = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Select plane to create the sketch.")
       
    Dim oSketch As PlanarSketch
    Set oSketch = oDef.Sketches.Add(planeEnt)
    
    Dim sketchName As String
    sketchName = InputBox("Give your new sketch a name", "Sketch Name", "Enter Sketch Name Here")
    oSketch.name = sketchName
    
    Dim feat As PartFeature
    Set feat = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFeatureFilter, "Select the feature to project")
    
    ' Iterate over the faces that were created by the feature.
    Dim usedEdges As ObjectCollection
    Set usedEdges = ThisApplication.TransientObjects.CreateObjectCollection
    Dim featFace As Face
    For Each featFace In feat.faces
        ' Iterate over the edges in the faces.
        Dim featEdge As Edge
        For Each featEdge In featFace.Edges
            ' Check to see if this edge has already been projected.
            Dim checkEdge As Edge
            Dim isUsed As Boolean
            isUsed = False
            For Each checkEdge In usedEdges
                If featEdge Is checkEdge Then
                    isUsed = True
                    Exit For
                End If
            Next
            
            If Not isUsed Then
                ' Project the edge onto the sketch.
                Call oSketch.AddByProjectingEntity(featEdge)
                
                ' Add this edge to the list of used edges.
                Call usedEdges.Add(featEdge)
            End If
        Next
    Next
End Sub
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com

They_Call_Me_Jake
Advocate
Advocate

@BrianEkins this works perfectly. Thank you very much.

0 Likes