Insert IFeature with workplane and workpoint

Insert IFeature with workplane and workpoint

martinhoos
Advocate Advocate
982 Views
7 Replies
Message 1 of 8

Insert IFeature with workplane and workpoint

martinhoos
Advocate
Advocate

Hello All,

i have a iFeature that i like to insert with an ilogical-code. The iFeature is called LongPilot, it formed the end of a tube. The tube diameters are 10, 12, 16 and 18mm.

I dont know how....

Thank you in advance.

Regards from germany

Martin

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

chandra.shekar.g
Autodesk Support
Autodesk Support

@martinhoos,

 

Try the following iLogic code. Before running code, make sure that path of ide file is updated.

 

Public Sub Main() 

	Dim oPartDoc As PartDocument 
	oPartDoc = ThisApplication.ActiveDocument 

	Dim oPartDef As PartComponentDefinition 
	oPartDef = oPartDoc.ComponentDefinition 

	Dim oWorkPoint As WorkPoint 
	oWorkPoint = oPartDef.WorkPoints("Center Point") 
	' Get the selected face to use as input for the iFeature. 
	Dim oFacePlane As WorkPlane 
	oFacePlane = oPartDef.WorkPlanes("XZ Plane") 

	Dim oFeatures As PartFeatures 
	oFeatures = oPartDef.Features 

	' Create an iFeatureDefinition object. 
	Dim oiFeatureDef As iFeatureDefinition 
	oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition("Path of ide file")

	' Set the input. 
	Dim oInput As iFeatureInput 
	For Each oInput In oiFeatureDef.iFeatureInputs 
		Dim oParamInput As iFeatureParameterInput 
		
		Select Case oInput.Name 
		Case "Durchmesser" 
		Dim oTubeDia As iFeatureParameterInput 
		oTubeDia = oInput 
		oTubeDia.Expression = "16 mm" 

		Case "Skizzierebene1" 
		Dim oPlaneInput As iFeatureSketchPlaneInput 
		oPlaneInput = oInput 
		oPlaneInput.PlaneInput = oFacePlane 

		Case "Referenzpunkt1" 

		Dim oRefPoint As iFeatureEntityInput 
		oRefPoint = oInput 
		oRefPoint.Entity = oWorkPoint 

		End Select 
	Next 

	' Create the iFeature. 
	Dim oiFeature As iFeature 
	oiFeature = oFeatures.iFeatures.Add(oiFeatureDef) 


End Sub

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 8

martinhoos
Advocate
Advocate

Hi chandra,

thank you very much for your reply... i tried your code, the ifeature is placed at the Center Point and XY plane.

Is there a possibility to choose a workpoint and a work plane while the code is running? May be a question like: "Pick a workpoint and a workplane"

Thank you for your help...

Regards Martin

0 Likes
Message 4 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@martinhoos,

 

Yes, you can try the following iLogic code.

 

Public Sub Main() 

	Dim oPartDoc As PartDocument 
	oPartDoc = ThisApplication.ActiveDocument 

	Dim oPartDef As PartComponentDefinition 
	oPartDef = oPartDoc.ComponentDefinition 

	Dim oWorkPoint As WorkPoint 
	oWorkPoint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kWorkPointFilter, "Select a point to place iFeature")  
	' Get the selected face to use as input for the iFeature. 
	Dim oFacePlane As WorkPlane 
	oFacePlane = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kWorkPlaneFilter, "Select a Plane to place iFeature") 

	Dim oFeatures As PartFeatures 
	oFeatures = oPartDef.Features 

	' Create an iFeatureDefinition object. 
	Dim oiFeatureDef As iFeatureDefinition 
	oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition("Path of ide file")

	' Set the input. 
	Dim oInput As iFeatureInput 
	For Each oInput In oiFeatureDef.iFeatureInputs 
		Dim oParamInput As iFeatureParameterInput 
		
		Select Case oInput.Name 
		Case "Durchmesser" 
		Dim oTubeDia As iFeatureParameterInput 
		oTubeDia = oInput 
		oTubeDia.Expression = "16 mm" 

		Case "Skizzierebene1" 
		Dim oPlaneInput As iFeatureSketchPlaneInput 
		oPlaneInput = oInput 
		oPlaneInput.PlaneInput = oFacePlane 

		Case "Referenzpunkt1" 

		Dim oRefPoint As iFeatureEntityInput 
		oRefPoint = oInput 
		oRefPoint.Entity = oWorkPoint 

		End Select 
	Next 

	' Create the iFeature. 
	Dim oiFeature As iFeature 
	oiFeature = oFeatures.iFeatures.Add(oiFeatureDef) 


End Sub

Please feel free to contact if there is any queries.

 

If solves problem, "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 5 of 8

martinhoos
Advocate
Advocate

Hello chandra,

thank you very much! Your code did it - great work....   🙂

Regards Martin

0 Likes
Message 6 of 8

martinhoos
Advocate
Advocate

Hello Chandra,

i have modified my iFeature but i did not get it runing. Please can you look at the code and modify it?

The iFeature shouldt match with copper pipes Ø10, Ø12, Ø16 and Ø18mm.

 

Regards Martin

 

0 Likes
Message 7 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@martinhoos,

 

Try below modified iLogic code with respect to previously attached iFeature file(.ide).

 

Public Sub Main() 

	Dim oPartDoc As PartDocument 
	oPartDoc = ThisApplication.ActiveDocument 

	Dim oPartDef As PartComponentDefinition 
	oPartDef = oPartDoc.ComponentDefinition 

	Dim oWorkPoint As WorkPoint 
	oWorkPoint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kWorkPointFilter, "Select a point to place iFeature")  
	' Get the selected face to use as input for the iFeature. 
	Dim oFacePlane As WorkPlane 
	oFacePlane = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kWorkPlaneFilter, "Select a Plane to place iFeature") 

	Dim oFeatures As PartFeatures 
	oFeatures = oPartDef.Features 

	' Create an iFeatureDefinition object. 
	Dim oiFeatureDef As iFeatureDefinition 
	oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition("Path of ide file")

	' Set the input. 
	Dim oInput As iFeatureInput 
	For Each oInput In oiFeatureDef.iFeatureInputs 
		Dim oParamInput As iFeatureParameterInput 
		
		Select Case oInput.Name 
		Case "durchmesser" 
		Dim oTubeDia As iFeatureParameterInput 
		oTubeDia = oInput 
		oTubeDia.Expression = "16 mm" 

		Case "Ebene1" 
		Dim oPlaneInput As iFeatureWorkPlaneInput 
		oPlaneInput = oInput 
		oPlaneInput.PlaneInput = oFacePlane 

		Case "Punkt1" 

		Dim oRefPoint As iFeatureEntityInput 
		oRefPoint = oInput 
		oRefPoint.Entity = oWorkPoint 

		End Select 
	Next 

	' Create the iFeature. 
	Dim oiFeature As iFeature 
	oiFeature = oFeatures.iFeatures.Add(oiFeatureDef) 


End Sub

Meanwhile, iFeature is failed to add into part document through UI as well. I think, model is failed to regenerate after updating parameter(durchmesser). On parameter update, below error is thrown.

 

Error.png

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 8

martinhoos
Advocate
Advocate

Hello Chandra,

thanks for your reply! I get the same fault - so i have to go back to our first solution.

Thanks a lot for your help.

Regards Martin

0 Likes