insert ifeature with ilogic

insert ifeature with ilogic

Anonymous
Not applicable
4,784 Views
19 Replies
Message 1 of 20

insert ifeature with ilogic

Anonymous
Not applicable

hi!

 

i want to insert a ifeatures with ilogic, my test code

 

' Get the part document and component definition of the active document.
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument
    
Dim oPartDef As PartComponentDefinition
oPartDef = oPartDoc.ComponentDefinition
    
' Get the selected face to use as input for the iFeature.
Dim oFace As Face
oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter,"SELECTIONNE Ta face" ) 
    
Dim oFeatures As PartFeatures
oFeatures = oPartDef.Features

' Create an iFeatureDefinition object.
Dim oiFeatureDef As iFeatureDefinition
oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition( _
"C:\IPSO2016\tab\PASSE_FILS.ide")
   
       ' Set the input.
    Dim oInput As iFeatureInput
    For Each oInput In oiFeatureDef.iFeatureInputs
        Dim oParamInput As iFeatureParameterInput
        Select Case oInput.Name
            Case "Sketch Position Plane1"
                Dim oPlaneInput As iFeatureSketchPlaneInput
                oPlaneInput = oInput
                oPlaneInput.PlaneInput = oFace
            Case "XA"
                oParamInput = oInput
                oParamInput.Expression = "1 in"
            Case "YA"
                oParamInput = oInput
                oParamInput.Expression = "0.5 in"
        End Select
    Next
	
' Create the iFeature.
Dim oiFeature As iFeature
oiFeature = oFeatures.iFeatures.Add(oiFeatureDef)

but dont work, anybody can help me?

 

thanks for your help!

0 Likes
Accepted solutions (1)
4,785 Views
19 Replies
Replies (19)
Message 3 of 20

Anonymous
Not applicable

Thanks for your link Geork!

 

But her code dont work in ilogic.

0 Likes
Message 4 of 20

LishuangLu
Autodesk
Autodesk

Here's the sample code that can create iFeature based on a planar face, you may first open a part with a cube or create a new part, then run below iLogic Rule. Let me know whether it works for you.

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 12804 StartFragment: 314 EndFragment: 12772 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

Public Sub Main()
    Dim oPartDoc As PartDocument
    oPartDoc = ThisApplication.ActiveDocument
    
    Dim oPartDef As PartComponentDefinition
    oPartDef = oPartDoc.ComponentDefinition
    
    ' Get the selected face to use as input for the iFeature.
    Dim oFace As Face
    oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a planar face")

    Dim oFeatures As PartFeatures
    oFeatures = oPartDef.Features
  
    ' Create an iFeatureDefinition object.
    Dim oiFeatureDef As iFeatureDefinition
    oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition( _
"C:\Users\Public\Documents\Autodesk\Inventor 2018\Catalog\Slots\End_mill_curved.ide")
    
    ' Set the input.
    Dim oInput As iFeatureInput
    For Each oInput In oiFeatureDef.iFeatureInputs
        Dim oParamInput As iFeatureParameterInput
        Select Case oInput.Name
            Case "Sketch Plane"
                Dim oPlaneInput As iFeatureSketchPlaneInput
                oPlaneInput = oInput
                oPlaneInput.PlaneInput = oFace
            Case "Diameter"
                oParamInput = oInput
                oParamInput.Expression = "1 in"
            Case "Depth"
                oParamInput = oInput
                oParamInput.Expression = "0.5 in"
        End Select
    Next
    
    ' Create the iFeature.
    Dim oiFeature As iFeature
    oiFeature = oFeatures.iFeatures.Add(oiFeatureDef)
End Sub

 Thanks,

-Lisa

0 Likes
Message 5 of 20

Anonymous
Not applicable

thanks for your reply 

 

 

 

 

    Dim oiFeatureDef As iFeatureDefinition
    oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition( _
"C:\IPSO2016\PASSE_FILS.ide")

 

0 Likes
Message 6 of 20

LishuangLu
Autodesk
Autodesk
Accepted solution

Does it work with Inventor's own iFeature file? If you are running with 2016, could you try with this iFeature "C:\Users\Public\Documents\Autodesk\Inventor 2016\Catalog\Slots\End_mill_curved.ide".

If above works, then it should be related with your iFeature, can you share the iFeature file with me for investigation?

 

Thanks,

-Lisa

Message 7 of 20

Anonymous
Not applicable

Yes work with that but i want to insert my custom ifeature in a specific place

0 Likes
Message 8 of 20

Anonymous
Not applicable

ok i find my problem 🙂

 

thansk again for your help 🙂

0 Likes
Message 9 of 20

Anonymous
Not applicable

anybody know if is possible to add a edge line selected axis direction in a code?

 

exemple:

 

Dim oFace As Face
oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "SELECTIONNE TON PART")
Dim oEdgeX As Edge 
oEdgeX = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "SELECTIONNE TA DIRECTION EN X.")
Dim oEdgeY As Edge 
oEdgeY = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "SELECTIONNE TA DIRECTION EN Y.")
Dim oFeatures As PartFeatures
oFeatures = oPartDef.Features
Dim oiFeatureDef As iFeatureDefinition
oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition("I:\DOCUMENTS\ARTICLES\REFERENCE\IFEATURES\TROUS TAB.ide")
Dim oInput As iFeatureInput
For Each oInput In oiFeatureDef.iFeatureInputs
Dim oParamInput As iFeatureParameterInput
Select Case oInput.Name
Case "FACE"
Dim oPlaneInput As iFeatureSketchPlaneInput
oPlaneInput = oInput
oPlaneInput.PlaneInput = oFace
Case "DIRECTION X"
Dim oEdgeInput As iFeatureEdgeInput
oEdgeInput = oInput
oEdgeInput.EdgeInput = oEdgeX
Case "DIRECTION Y"
Dim oEdgeInput As iFeatureEdgeInput
oEdgeInput = oInput
oEdgeInput.EdgeInput = oEdgeY
End Select
Next

thanks for your help 🙂

0 Likes
Message 10 of 20

LishuangLu
Autodesk
Autodesk

Hi,

 

According to my investigation, there's no such iFeatureEdgeInput API object being exposed for doing this thing.

However, there's iFeatureEntityInput object that should take the edge object as entity, but when I tried declare iFeatureEntityInput and pass the edge object as Entity, I still get error when create the iFeature, looks there's something wrong in above logic. I guess this is a bug which hasn't been well implemented.

I'm going to track a bug into our internal bug system and ask our developer for investigation and fixing. So for now, we have no way to use a edge line as the  axis direction for iFeature creation. Sorry for the inconvenience.

 

Thanks,

-Lisa

0 Likes
Message 11 of 20

Anonymous
Not applicable

maybe it's possible with the part work axis x and y?

0 Likes
Message 12 of 20

Anonymous
Not applicable

ok i find my solution, i put the vertex axis in the part referenche sketch before i extract the ifeature and work great 🙂

 

thanks for all your help again!

0 Likes
Message 13 of 20

Anonymous
Not applicable

a ton of questions lol

 

 

I have another one, now i trying to change the position angle when i add my ifeature

 

my code work but with a differente angle?

 

Dim oInput As iFeatureInput
For Each oInput In oiFeatureDef.iFeatureInputs
Dim oParamInput As iFeatureParameterInput
Select Case oInput.Name
Case "Sketch Plane1"
Dim oPlaneInput As iFeatureSketchPlaneInput
oPlaneInput = oInput
oPlaneInput.PlaneInput = oFace
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
oPlaneInput.SetPosition(oTG.CreatePoint(0, 0, 0),oTG.CreateVector(1, 0, 0), 180)
End Select

 i want a position angle of 180 degre and my result is 53,24031 degre???

0 Likes
Message 14 of 20

martinhoos
Advocate
Advocate

Hi Lisa,

i am new with iFeature and iFeature place in.

I try to change your code that it works for me - without success! The iFeature i created is for the ends of Pipelines with the diameter 10, 12, 16 or 18mm. That means, i have pipelins with this diameters and i like to have the iFeature fixed to an end of this pipes regarding to the original diameter.

Please can you help me to get my Problem fixed?

Thank you very much....

Regards

Martin

 

 

0 Likes
Message 15 of 20

LishuangLu
Autodesk
Autodesk

@martinhoos, not sure whether I understand your requirement, so I tried to add the iFeature into the back face of your attached part with the position set to the center point of the back face with below VBA code. (Create a workpoint based on the back face first, then run the vba code and select the back face)

However, I got failure when run to the last code, and by confirming with our API team member, there seems to be a bug. Please let me know whether I understand your requirement.

Public Sub Main()

    Dim oPartDoc As PartDocument

    Set oPartDoc = ThisApplication.ActiveDocument

   

    Dim oPartDef As PartComponentDefinition

    Set oPartDef = oPartDoc.ComponentDefinition

   

    Dim oTG As TransientGeometry

    Set oTG = ThisApplication.TransientGeometry

   

    Dim oVector As Vector

    Set oVector = oTG.CreateVector(0, 1, 0)

   

    Dim oPoint As Point

    Set oPoint = oPartDef.WorkPoints("Work Point1").Point

   

    ' Get the selected face to use as input for the iFeature.

    Dim oFace As Face

    Set oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a planar face")

 

    Dim oFeatures As PartFeatures

    Set oFeatures = oPartDef.Features

 

    ' Create an iFeatureDefinition object.

    Dim oiFeatureDef As iFeatureDefinition

    Set oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition("C:\Users\Public\Documents\Autodesk\Inventor 2019\Catalog\Punches\curved slot.ide")

    ' Set the input.

    Dim oInput As iFeatureInput

    For Each oInput In oiFeatureDef.iFeatureInputs

        Dim oParamInput As iFeatureParameterInput

        Select Case oInput.Name

            Case "Profile Plane1"

                Dim oPlaneInput As iFeatureSketchPlaneInput

                Set oPlaneInput = oInput

                oPlaneInput.PlaneInput = oFace

                Call oPlaneInput.SetPosition(oPoint, oVector, 0)

            Case "Diameter"

                Set oParamInput = oInput

                oParamInput.Expression = "1 in"

            Case "Depth"

                Set oParamInput = oInput

                oParamInput.Expression = "0.5 in"

        End Select

    Next

   

    ' Create the iFeature.

    Dim oiFeature As iFeature

    Set oiFeature = oFeatures.iFeatures.Add(oiFeatureDef)

End Sub

0 Likes
Message 16 of 20

martinhoos
Advocate
Advocate

Hi Lisa,

thanks for your reply and for your help. I try to explain my Problem. I have a pipe

 

longpilot_1.jpg

I like to insert the iFeature called "LongPilot_EXT.ide"  by selecting the pipe face and a point in the center of the pipe

 

longpilot_2.jpg

 

 

The result Looks like

 

longpilot_3.jpg

Enclose you will find the iFeature that i like to use.

 

Thanks again for your help.

Regards

Martin

 

 

0 Likes
Message 17 of 20

LishuangLu
Autodesk
Autodesk

Hi Martin, 

Thanks for sharing more information! Based on my understanding, the VBA code provided by me can satisfy your requirement, but we have bug in creating such kind of iFeature through API right now. I will create a bug and ask our developer to do more investigation. Sorry for the inconvenience. 

 

Thanks, 

-Lisa

0 Likes
Message 18 of 20

martinhoos
Advocate
Advocate

Hi Lisa,

thanks for your reply. Bad news  - so we have to wait for the developer!

Regards from germany

Martin

 

PS: ... it is so close to Christmas - may be santa claus is bringing a solution . Wish you merry Christmas...

0 Likes
Message 19 of 20

LishuangLu
Autodesk
Autodesk

Thanks for your understanding, Martin! 

Wish you merry Christmas! 🙂

Regards, 

-Lisa

0 Likes
Message 20 of 20

tech
Explorer
Explorer

Hi LishuangLu,

in your example you define one iFeatureSketchPlaneInput and two iFeatureParameterInput.
Is it possible define two iFeatureSketchPlaneInput, one for the Sketch and one for a work plane?

Many thanks!
Saulo

0 Likes