PartFeatures ilogic

PartFeatures ilogic

Anonymous
Not applicable
990 Views
15 Replies
Message 1 of 16

PartFeatures ilogic

Anonymous
Not applicable

I want to copy features after Extrude4 from part1 to part2 by ilogic code.

I think this simple example is a very complicated task so any at all help will be appriciated.

Any sample code about copying parts features or anything would also help

 

0 Likes
991 Views
15 Replies
Replies (15)
Message 2 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Actually, there is no direct Inventor API or iLogic code to copy extrude from one part to another part. But details or contents of sketch and extrude can retrieved through Inventor API or iLogic code. Later with same details or contents, sketch and extrude can be recreated.

 

On the other hand, creating iFeature in source part and inserting the same iFeature into destination part would be helpful.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 16

Anonymous
Not applicable

You mentioned:

"But details or contents of sketch and extrude can retrieved through Inventor API or iLogic code. Later with same details or contents, sketch and extrude can be recreated."

 

I am interested in this method. Do you have any sample code of this?

 

 

 

0 Likes
Message 4 of 16

Anonymous
Not applicable

 @

0 Likes
Message 5 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Can you please give steps to copy extrude from one part to another part through UI? Based on this, required Inventor API can be identified.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 16

Anonymous
Not applicable

 The first tree features in part1 are extrusions so for starters i would want to make a code something like this:

 

SyntaxEditor Code Snippet

'Part1 is the active file
'Part2 file is a copy of part1 file with less features


Name1="D:\!Main Project\Workspace\Test\Part1"
Name2="D:\!Main Project\Workspace\Test\Part2"

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oFeatures As PartFeatures
oFeatures = oDoc.ComponentDefinition.Features

For Each oFeature In oFeatures

'check if it is an extrusion

If oFeature.Type=83910656  Then 
    'If feature exist in part2 

        'do nothing

    'Else

        'Collect information of feature in part1

        'Make extrusion of feature with the collected information in part2

    'end if

End If
Next

 

 

0 Likes
Message 7 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

To extrude feature through Inventor API, it needs sketch definition and sketch entities (lines, arcs, etc). After creation of sketch, sketch should be closed loop. Try below VBA code to recreate extrude feature in part.

 

 

Public Sub ExtrudeFeature()
     ' Create a new part document, using the default part template.
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
                ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))

    ' Set a reference to the component definition.
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oPartDoc.ComponentDefinition

    ' Create a new sketch on the X-Y work plane.
    Dim oSketch As PlanarSketch
    Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(3))

    ' Set a reference to the transient geometry object.
    Dim oTransGeom As TransientGeometry
    Set oTransGeom = ThisApplication.TransientGeometry
    Dim oCenter As Point2d
    Set oCenter = oTransGeom.CreatePoint2d(0, 0)

    ' Create a sketch circle
    Dim oCircle As SketchCircle
    Set oCircle = oSketch.SketchCircles.AddByCenterRadius(oCenter, 1)

    Dim oProfile As Profile
    Set oProfile = oSketch.Profiles.AddForSolid

    ' Create a base extrusion 4 cm thick.
    Dim oExtrudeDef As ExtrudeDefinition
    Set oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kJoinOperation)
    Call oExtrudeDef.SetDistanceExtent(1, kPositiveExtentDirection)
    Dim oExtrude As ExtrudeFeature
    Set oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 16

Anonymous
Not applicable

  I already know about this example from the API it dosen't solve the main problem.

 

The Main problem is:

 

-to get the extrude sketch and extrude information from part1

-copy or create the extrude sketch into the existing extrude in part2

-create the estrude in part two with the information

 

             

0 Likes
Message 9 of 16

Anonymous
Not applicable

I have started writing the code for copying extrusion features into a part. Got to start small.... 🙂 For now I want to copy the extrusion sketch and information into the new part. It's not going as planned

 

Any help with the code?

 

 

SyntaxEditor Code Snippet

filename="D:\!Main project\!Test No.3\Part5.ipt"
PartDoc=ThisApplication.ActiveDocument
PartcompDef=PartDoc.ComponentDefinition
ExtFeature=PartcompDef.Features.ExtrudeFeatures.item(1)
Dim ExtDef As ExtrudeDefinition =ExtFeature.Definition
ExtProfile=ExtDef.Profile

Dim osketch As Planarsketch
oSketchToCopy=ExtFeature.Definition.Profile.Parent


Dim oSketchObjects As ObjectCollection
oSketchObjects = ThisApplication.TransientObjects.CreateObjectCollection

For Each oProfPath In ExtDef.Profile
    'oSketchObjects.Add(oProfPath)
     For i=1 To oProfPath.count
       oSketchObjects.Add(oProfPath.Item(i).SketchEntity)
    Next
Next

asm = ThisApplication.Documents.Open(filename,True)
Dim Sketch2 As Planarsketch
Sketch2 = asm.ComponentDefinition.Sketches.Add(asm.ComponentDefinition.WorkPlanes.Item(1),False)
oSketchToCopy.CopyContentsTo(Sketch2)
oProfile = Sketch2.Profiles.AddForSolid(False,oSketchObjects)
Dim extrudeDef = PartcompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kNewBodyOperation)
extrudeDef.SetDistanceExtent(ExtFeature.Definition.Extent.Distance, ExtFeature.Definition.Extent.Direction)
oF2 = asm.ComponentDefinition.Features.ExtrudeFeatures.Add(extrudeDef)

 

 

0 Likes
Message 10 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Little changes made to iLogic code and works fine

filename="Path of file\Part2.ipt"
PartDoc=ThisApplication.ActiveDocument
PartcompDef=PartDoc.ComponentDefinition
ExtFeature=PartcompDef.Features.ExtrudeFeatures.item(1)
Dim ExtDef As ExtrudeDefinition =ExtFeature.Definition
ExtProfile=ExtDef.Profile

Dim osketch As PlanarSketch
oSketchToCopy=ExtFeature.Definition.Profile.Parent
 

asm = ThisApplication.Documents.Open(filename,True)
Dim Sketch2 As PlanarSketch
Sketch2 = asm.ComponentDefinition.Sketches.Add(asm.ComponentDefinition.WorkPlanes.Item(1),False)
oSketchToCopy.CopyContentsTo(Sketch2)

oProfile = Sketch2.Profiles.AddForSolid

Dim extrudeDef = PartcompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kNewBodyOperation)
extrudeDef.SetDistanceExtent(ExtFeature.Definition.Extent.Distance, ExtFeature.Definition.Extent.Direction)
oF2 = asm.ComponentDefinition.Features.ExtrudeFeatures.Add(extrudeDef)

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 11 of 16

Anonymous
Not applicable

 I have aded these lines of code

TransientObjects.CreateObjectCollection

because if i understood correctly,if i have multiple profiles in a sketch and i have to tell inventor which profile to extrude???

 

Dim oSketchObjects As ObjectCollection
oSketchObjects = ThisApplication.TransientObjects.CreateObjectCollection

For Each oProfPath In ExtDef.Profile
    'oSketchObjects.Add(oProfPath)
     For i=1 To oProfPath.count
       oSketchObjects.Add(oProfPath.Item(i).SketchEntity)
    Next
Next

 

 

 

Message 12 of 16

Anonymous
Not applicable

 

 

SyntaxEditor Code Snippet

filename="D:\!Main Project\Workspace\Test\Part2.ipt"

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oFeatures As PartFeatures
oFeatures = oDoc.ComponentDefinition.Features

Dim oSelectSet As SelectSet 
oSelectSet = oDoc.SelectSet
oSelectSet.Clear 

Dim oFeature As PartFeature
For Each oFeature In oFeatures
If oFeature.Type=objecttypeenum.kExtrudeFeatureObject
oSelectSet.Select(oFeature)

Dim oCopyControlDef As ControlDefinition
oCopyControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppCopyCmd")
oCopyControlDef.Execute
asm = ThisApplication.Documents.Open(filename,True)
Dim oPasteControlDef As ControlDefinition
Dim xyPlane As Inventor.WorkPlane 
xyPlane = asm.ComponentDefinition.WorkPlanes.Item(3) 

Dim oSelectSet1 As SelectSet 
oSelectSet1 = asm.SelectSet
oSelectSet1.Select(xyPlane)

oPasteControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppPasteCmd")
oPasteControlDef.Execute

Dim oPasteControlDef1 As ControlDefinition
oPasteControlDef1 = ThisApplication.CommandManager.ControlDefinitions.Item("AppCGUCS_CreateCmd")
oPasteControlDef1.Execute2(True)

Exit Sub
End If

Next

 

 

0 Likes
Message 13 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Hoping that below iLogic code may be helpful.

 

filename="D:\!Main Project\Workspace\Test\Part2.ipt"

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oFeatures As PartFeatures
oFeatures = oDoc.ComponentDefinition.Features

Dim oSelectSet As SelectSet 
oSelectSet = oDoc.SelectSet
oSelectSet.Clear 

Dim oFeature As PartFeature
For Each oFeature In oFeatures
If oFeature.Type=objecttypeenum.kExtrudeFeatureObject
oSelectSet.Select(oFeature)

Dim oCopyControlDef As ControlDefinition
oCopyControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppCopyCmd")
oCopyControlDef.Execute
asm = ThisApplication.Documents.Open(filename,True)
Dim oPasteControlDef As ControlDefinition
Dim xyPlane As Inventor.WorkPlane 
xyPlane = asm.ComponentDefinition.WorkPlanes.Item(3) 

Dim oSelectSet1 As SelectSet 
oSelectSet1 = asm.SelectSet
oSelectSet1.Select(xyPlane)

oPasteControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppPasteCmd")
oPasteControlDef.Execute

filename="D:\!Main Project\Workspace\Test\Part2.ipt"

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oFeatures As PartFeatures
oFeatures = oDoc.ComponentDefinition.Features

Dim oSelectSet As SelectSet 
oSelectSet = oDoc.SelectSet
oSelectSet.Clear 

Dim oFeature As PartFeature
For Each oFeature In oFeatures
If oFeature.Type=objecttypeenum.kExtrudeFeatureObject
oSelectSet.Select(oFeature)

Dim oCopyControlDef As ControlDefinition
oCopyControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppCopyCmd")
oCopyControlDef.Execute
asm = ThisApplication.Documents.Open(filename,True)
Dim oPasteControlDef As ControlDefinition
Dim xyPlane As Inventor.WorkPlane 
xyPlane = asm.ComponentDefinition.WorkPlanes.Item(3) 

Dim oSelectSet1 As SelectSet 
oSelectSet1 = asm.SelectSet
oSelectSet1.Select(xyPlane)

oPasteControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppPasteCmd")
oPasteControlDef.Execute

Dim oPasteControlDef1 As ControlDefinition
oPasteControlDef1 = ThisApplication.CommandManager.ControlDefinitions.Item("AppCGUCS_CreateCmd")
oPasteControlDef1.Execute2(True)

Dim oFinish As ControlDefinition
oFinish = ThisApplication.CommandManager.ControlDefinitions.Item("UnknownUCxFinishActiveCommand")
oFinish.Execute2(True)

Exit Sub
End If

Next



Exit Sub
End If

Next

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 14 of 16

Anonymous
Not applicable
 

 

 
0 Likes
Message 15 of 16

Anonymous
Not applicable
 

 

0 Likes
Message 16 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Code is wokring fine except activating "Finish" button. Pleas log this wish list at idea station using below link.

 

https://forums.autodesk.com/t5/inventor-ideas/idb-p/v1232

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes