iFeature - add via iLogic - possible ??

iFeature - add via iLogic - possible ??

ralfmja
Advocate Advocate
723 Views
3 Replies
Message 1 of 4

iFeature - add via iLogic - possible ??

ralfmja
Advocate
Advocate

Hello all,

 

I have simple iFeature (look on attached gif file) and I want to insert it via Ilogic.

 

First of all - I want ask - it is possible ??

 

Indicates the element's plane and two holes (screen below):

 

obraz.png

It also measures the diameter of the hole (I do not want to enter or enter it would only have to be the result of the measurement) which is the only parameter in this case.

obraz.png

 

I found a code (wihich prepare by @chandra.shekar.g ) that I could probably use but I don't know how to define "holes" and how to define a parameter that is the result of a measurement.

 

https://forums.autodesk.com/t5/inventor-customization/placing-ifeature-using-ilogic/m-p/8969384/high... 

 

Will anyone be so kind and help me ??

 

The attachment also adds a file with iFeature in ide format and sample part with 2 hole.

 

Thanks in advance,

Cheers,

ralfmj

0 Likes
Accepted solutions (1)
724 Views
3 Replies
Replies (3)
Message 2 of 4

ralfmja
Advocate
Advocate

Hi,

 

Sorry for that but I do it.

 

Now only problem for me is how to measure diameter of the hole ??

 

obraz.png

 

Actually in code I use inputBox but it's not that what I' expected 🙂

 

Below my code:

Public Sub Main()
		
		oPath = "C:\FASOLKA.ide"
		oDefault = "8"
        Dim oPartDoc As PartDocument
        oPartDoc = ThisApplication.ActiveEditDocument

        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, "Wybierz płaszczyzne na której powstanie fasolka")

        'Wybierz otwór 1
        Dim oOs1 As Object
         oOs1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceCylindricalFilter, "Wybierz otwór 1")
		
		'Wybierz otwór 2
        Dim oOs2 As Object
         oOs2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceCylindricalFilter, "Wybierz otwór 2")

        Dim oFeatures As PartFeatures
         oFeatures = oPartDef.Features

        ' Create an iFeatureDefinition object.
        Dim oiFeatureDef As iFeatureDefinition
         oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition(oPath)

        ' Set the input.
        Dim oInput As iFeatureInput
        For Each oInput In oiFeatureDef.iFeatureInputs
            Dim oParamInput As iFeatureParameterInput

            Select Case oInput.Name
                Case "OS 1"
                    Dim oOs1Input As iFeatureEntityInput
                    'Dim oPlaneInput As iFeatureSketchPlaneInput
                    oOs1Input = oInput
                    oOs1Input.Entity = oOs1
					 
                Case "OS 2"
                    Dim oOs2Input As iFeatureEntityInput
                    'Dim oPlane1Input As iFeatureSketchPlaneInput
                    oOs2Input = oInput
                    oOs2Input.Entity = oOs2
					 
                Case "PŁASZCZYZNA"
                    Dim oPlaneInput As iFeatureWorkPlaneInput
                    'Dim oPlane1Input As iFeatureSketchPlaneInput
                    oPlaneInput = oInput
                    oPlaneInput.PlaneInput = oFace
					 
                Case "SREDNICA"
					oSrednica = InputBox("Wpisz srednice fasolki","SREDNICA", oDefault)
                    oParamInput = oInput
                    oParamInput.Expression = oSrednica
					 
            End Select
        Next
		 

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

Thanks,

ralfmj

0 Likes
Message 3 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@ralfmja,

 

Try below changes in iLogic code to measure diameter of selected holes.

 

Public Sub Main()
		
		oPath = "C:\FASOLKA.ide"
		oDefault = "8"
        Dim oPartDoc As PartDocument
        oPartDoc = ThisApplication.ActiveEditDocument

        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, "Wybierz płaszczyzne na której powstanie fasolka")

        'Wybierz otwór 1
        Dim oOs1 As Face 
         oOs1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceCylindricalFilter, "Wybierz otwór 1")
		
		Dim oCylinder As Cylinder 
		oCylinder = oOs1.Geometry 
		
		MessageBox.Show("Diameter :" &(oCylinder.Radius * 2).ToString())
		
		'Wybierz otwór 2
        Dim oOs2 As Face 
        oOs2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceCylindricalFilter, "Wybierz otwór 2")
		
		oCylinder = oOs2.Geometry 
		
		MessageBox.Show("Diameter :" & (oCylinder.Radius * 2).ToString())
		
        Dim oFeatures As PartFeatures
         oFeatures = oPartDef.Features

        ' Create an iFeatureDefinition object.
        Dim oiFeatureDef As iFeatureDefinition
         oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition(oPath)

        ' Set the input.
        Dim oInput As iFeatureInput
        For Each oInput In oiFeatureDef.iFeatureInputs
            Dim oParamInput As iFeatureParameterInput

            Select Case oInput.Name
                Case "OS 1"
                    Dim oOs1Input As iFeatureEntityInput
                    'Dim oPlaneInput As iFeatureSketchPlaneInput
                    oOs1Input = oInput
                    oOs1Input.Entity = oOs1
					 
                Case "OS 2"
                    Dim oOs2Input As iFeatureEntityInput
                    'Dim oPlane1Input As iFeatureSketchPlaneInput
                    oOs2Input = oInput
                    oOs2Input.Entity = oOs2
					 
                Case "PŁASZCZYZNA"
                    Dim oPlaneInput As iFeatureWorkPlaneInput
                    'Dim oPlane1Input As iFeatureSketchPlaneInput
                    oPlaneInput = oInput
                    oPlaneInput.PlaneInput = oFace
					 
                Case "SREDNICA"
					oSrednica = InputBox("Wpisz srednice fasolki","SREDNICA", oDefault)
                    oParamInput = oInput
                    oParamInput.Expression = oSrednica
					 
            End Select
        Next
		 

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

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 4

ralfmja
Advocate
Advocate

Hi @chandra.shekar.g ,

 

Thank you - I upgrade my code and works perfect 🙂

 

Public Sub Main()
		
		oPath = "C:\FASOLKA.ide"
		
        Dim oPartDoc As PartDocument
        oPartDoc = ThisApplication.ActiveEditDocument

        Dim oPartDef As PartComponentDefinition
         oPartDef = oPartDoc.ComponentDefinition

        ' Wybierz płaszczyzne na której powstanie fasolka
        Dim oFace As Face
         oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Wybierz płaszczyzne na której powstanie fasolka")

        'Wybierz otwór 1
        Dim oOs1 As Object
         oOs1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceCylindricalFilter, "Wybierz otwór 1")
		
		'Wybierz otwór 2
        Dim oOs2 As Object
         oOs2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceCylindricalFilter, "Wybierz otwór 2")

        Dim oFeatures As PartFeatures
         oFeatures = oPartDef.Features

        ' Create an iFeatureDefinition object.
        Dim oiFeatureDef As iFeatureDefinition
         oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition(oPath)

        ' Set the input.
        Dim oInput As iFeatureInput
        For Each oInput In oiFeatureDef.iFeatureInputs
            Dim oParamInput As iFeatureParameterInput

            Select Case oInput.Name
                Case "OS 1"
                    Dim oOs1Input As iFeatureEntityInput
                    'Dim oPlaneInput As iFeatureSketchPlaneInput
                    oOs1Input = oInput
                    oOs1Input.Entity = oOs1
					 
                Case "OS 2"
                    Dim oOs2Input As iFeatureEntityInput
                    'Dim oPlane1Input As iFeatureSketchPlaneInput
                    oOs2Input = oInput
                    oOs2Input.Entity = oOs2
					 
                Case "PŁASZCZYZNA"
                    Dim oPlaneInput As iFeatureWorkPlaneInput
                    'Dim oPlane1Input As iFeatureSketchPlaneInput
                    oPlaneInput = oInput
                    oPlaneInput.PlaneInput = oFace
					 
                Case "SREDNICA"
  					oSrednica = oOs1.Geometry.Radius * 10 * 2
					oParamInput = oInput
                    oParamInput.Expression = oSrednica
					 
            End Select
        Next
		 
        ' Create the iFeature.
        Dim oiFeature As iFeature
        oiFeature = oFeatures.iFeatures.Add(oiFeatureDef)
    End Sub

Regards,

ralfmj

0 Likes