Ilogic-How to choose plane and point iFeature (code)

Ilogic-How to choose plane and point iFeature (code)

Anonymous
Not applicable
1,246 Views
7 Replies
Message 1 of 8

Ilogic-How to choose plane and point iFeature (code)

Anonymous
Not applicable

I want insert iFeature into Part. But i don't know code choose Plane and Point. Please help me!!!Capture.PNG

0 Likes
Accepted solutions (1)
1,247 Views
7 Replies
Replies (7)
Message 2 of 8

Michael.Navara
Advisor
Advisor
0 Likes
Message 3 of 8

Anonymous
Not applicable

Thank you.

But it isn't " Pick Point" . I dont know define Point Refence iFeature. Can help me!!!

0 Likes
Message 4 of 8

Michael.Navara
Advisor
Advisor
Accepted solution

Full example is in attachment

'Active part
Dim partDoc As PartDocument = ThisDoc.Document
Dim partDef As PartComponentDefinition = partDoc.ComponentDefinition

'Placement sources
Dim oSketch As PlanarSketch = partDef.Sketches("iFeatureTargetSketch")
Dim oFace As Face = oSketch.PlanarEntity
Dim oPoint As SketchPoint = oSketch.SketchPoints(1)

'iFeature creation
Dim iFeatureFileName As String = System.IO.Path.GetDirectoryName(partDoc.FullFileName) & "\Test.ide"
Dim iFeatureDef As iFeatureDefinition = partDef.Features.iFeatures.CreateiFeatureDefinition(iFeatureFileName)

For Each iFeaInput As iFeatureInput In iFeatureDef.iFeatureInputs
	
	'Explanation. See iLogic log window
	Logger.Debug("Expected entities for " & iFeaInput.Name & ": " & vbCrLf  & iFeaInput.EntityType.ToString("F").Replace(", ", vbCrLf))
	
	Select Case iFeaInput.Name
	Case "Plane"
		Dim planeInput As iFeatureSketchPlaneInput = iFeaInput 
		planeInput.PlaneInput = oFace
	Case "Point"
		Dim pointInput As iFeatureEntityInput = iFeaInput 
		pointInput.Entity = oPoint
	End Select
	
Next

partDef.Features.iFeatures.Add(iFeatureDef)

 

Message 5 of 8

Anonymous
Not applicable

Thanks . I tried my best. But it's buggy, I don't fix them. I am using Inventor 2019 so I can't open your file. I send you my file. Can you check it out for me? Rules = iFeature

code

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

Dim oPartDef As PartComponentDefinition
oPartDef = oPartDoc.ComponentDefinition


Dim oPlane As WorkPlane = oPartDef.WorkPlanes.Item("YZ Plane")
Dim oPoint As WorkPoint = oPartDef.WorkPoints.Item("Center Point")
Dim oFeatures As PartFeatures
oFeatures = oPartDef.Features

Dim oiFeatureDef As iFeatureDefinition
oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition("C:\Users\Public\Documents\Autodesk\Inventor 2019\Catalog\TAVO\LINK PIPE\DN125SCH40.ide")
Dim oInput As iFeatureInput

For Each oInput In oiFeatureDef.iFeatureInputs
Dim oParamInput As iFeatureParameterInput
Select Case oInput.Name
Case "Plane1"
Dim oPlaneInput As iFeatureSketchPlaneInput=oInput
oPlaneInput.PlaneInput = oPlane
Case "Point1"
Dim pointInput As iFeatureEntityInput = oInput
pointInput.Entity = oPoint
Case "Angle_position"
oParamInput = oInput
oParamInput.Expression = "90 deg"
Case "Lenght_pipe"
oParamInput = oInput
oParamInput.Expression = "200 mm"
Case "Position_hold"
oParamInput = oInput
oParamInput.Expression = "500 mm"
Case "R_tank"
oParamInput = oInput
oParamInput.Expression = diameter/2
Case "Thick"
oParamInput = oInput
oParamInput.Expression = Thickness
End Select
Next
Dim oiFeature As iFeature
oiFeature = oFeatures.iFeatures.Add(oiFeatureDef)

0 Likes
Message 6 of 8

Michael.Navara
Advisor
Advisor

You need to set appropriate variable type.

 

Here is the change

 

 

 

...
Select Case oInput.Name
    Case "Plane1"
        'This iFeatureInput is iFeatureWorkPlaneInput (NOT iFeatureSketchPlaneInput)
        Logger.Debug(oInput.Type.ToString("F"))
        Dim oPlaneInput As iFeatureWorkPlaneInput = oInput
        oPlaneInput.PlaneInput = oPlane
...     

 

 

 

The second bug is in setting .Expression. This must be a string (NOT double) and unit specifier is recomended

 

 

 

...
Case "R_tank"
    oParamInput = oInput
    oParamInput.Expression = string.format("{0} mm", diameter/2 *10) ' diameter

Case "Thick"
    oParamInput = oInput
    oParamInput.Expression =  string.format("{0} mm", Thickness *10) 'Thickness
...

 

Message 7 of 8

Anonymous
Not applicable

That is a wonderful thing for me. Thank you very much. I have a question, I don't know if that variable exists. how do I know the variable name. While writing code on Inventor it does not show variable options. For example, I know the face I selected is Plane but I don't know the variable named iFeatureWorkPlaneInput. Can you share your experiences and materials? Once again thank you very much.

0 Likes
Message 8 of 8

Michael.Navara
Advisor
Advisor

Documentation for Inventor API is available locally in SDK or online 

https://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-6FD7AA08-1E43-43FC-971B-5F20E56C8846

I use VBA tools (Locals and Watch windows) for better understanding of object structure. This tools are very handy.

 

For general information for VB.NET I use standard sources (MSDN, StackOverflow,...)

 

But experience is not shareable 😐