Change Extrude Feature Dimension.

Change Extrude Feature Dimension.

Luis_Pacheco_3D
Advocate Advocate
484 Views
5 Replies
Message 1 of 6

Change Extrude Feature Dimension.

Luis_Pacheco_3D
Advocate
Advocate

Hi, I want to change the value  "distance A" of the feature called "RIP_L",  

Luis_Pacheco_3D_0-1689109171909.png

 

The Feature exists, and the process would be the following.

 

1. Pick the part in an assembly, verify if exist the feature in the part and then get the value of the "Distance A"

2. Place the new value through an input box and change it

 

I have been trying some codes but it always shows me an error. I need your help with this issue. Thanks.

0 Likes
485 Views
5 Replies
Replies (5)
Message 2 of 6

Curtis_Waguespack
Consultant
Consultant

Hi @Luis_Pacheco_3D 

 

Here is a quick example of how to do this:

 

First, I have a part that has an extrude feature, and I renamed the value/parameter for distance A to "Length", as shown:

Curtis_Waguespack_1-1689110997724.png

 

 

Curtis_Waguespack_0-1689110955022.png

 

 

In the assembly, I have a User Parameter called Length, as shown:

Curtis_Waguespack_2-1689111085457.png

 

I have a rule in the assembly that has this line of code:

 

Curtis_Waguespack_3-1689111521120.png

 

and the assembly has a form such as this:

 

Curtis_Waguespack_4-1689111577025.png

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 3 of 6

Luis_Pacheco_3D
Advocate
Advocate

Thanks for your response, I can create the new parameter through ilogic because is a lot of parts, but how can I associate the new parameter to the extrude feature?

Message 4 of 6

Curtis_Waguespack
Consultant
Consultant

Hi @Luis_Pacheco_3D 

 

My apologies, I got side tracked when reading your post and missed the objective completely.

 

This might work for you, but there is likely a better method. Hopefully someone else can take what I have here and come up with a better way.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim oOcc As ComponentOccurrence
oOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select a component")
If oOcc Is Nothing Then Exit Sub


Dim oDoc As PartDocument
oDoc = oOcc.Definition.Document

Dim oFeature As PartFeature
Dim oParam As Parameter
Dim oSketch As PlanarSketch
Dim oDimensionConstraints As New ArrayList

For Each oFeature In oDoc.ComponentDefinition.Features
	If oFeature.Name = "RIP_L" Then
		oSketch = oFeature.Profile.Parent

		For Each oDim In oSketch.DimensionConstraints
			'Logger.Info(oDim.parameter.name)
			oDimensionConstraints.Add(oDim.parameter.name)
		Next

		For Each oParam In oFeature.Parameters
			If oDimensionConstraints.Contains(oParam.name) Then Continue For
			If oParam.units = "deg" Then Continue For
			Logger.Info(oParam.name)
			Logger.Info(oParam.units)

			oParam.Value = Length

		Next
	End If
Next

 

EESignature

Message 5 of 6

Luis_Pacheco_3D
Advocate
Advocate

I´m trying to do something like this,

 

 

Sub main 
Dim oPart As ComponentOccurrence
oPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select a component")
If Feature.IsActive(oPart.Name, "RIP_L") Then
MessageBox.Show("Existe", "Title")
CambiarDato(oPart) 
Else 
End If 
End Sub 

Private Sub CambiarDato(oPart As ComponentOccurrence)
	Dim oPartDoc As PartDocument
	Dim oCompDef As PartComponentDefinition
	Dim oExtrude As ExtrudeFeature
	Dim oDistance As String

		oDistance = InputBox("Prompt", "Title", "Default Entry")
		
		oExtrude=oCompDef.Features.ExtrudeFeatures.Item("RIP_L")
		oExtrude.Definition.SetDistanceExtent(oDistance, kNegativeExtentDirection)
	End Sub 

 

 

But on Line 19 and 20 show me this error:

 

 

Error in rule: Rule2, in document: FP-WS3-9.04.iam

Object reference not set to an instance of an object.

 

 

 

System.NullReferenceException: Object reference not set to an instance of an object.
   at ThisRule.CambiarDato(ComponentOccurrence oPart)
   at ThisRule.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

 

The code on the private sub works perfectly in a part instance but in assembly does not work. 

0 Likes
Message 6 of 6

Luis_Pacheco_3D
Advocate
Advocate

 

Sub Main()
    Dim oPart As ComponentOccurrence
    oPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select a component")
    
    If Feature.IsActive(oPart.Name, "RIP_L") Then
        MessageBox.Show("Existe", "Title")
        CambiarDato(oPart)
    End If
End Sub

Private Sub CambiarDato(oPart As ComponentOccurrence)
    Dim oCompDef As PartComponentDefinition
    Dim oExtrude As ExtrudeFeature
    Dim oDistance As String

    oCompDef = oPart.Definition
    oDistance = InputBox("Prompt", "Title", "Default Entry")
    
    If Not oCompDef Is Nothing Then
        oExtrude = oCompDef.Features.ExtrudeFeatures.Item("RIP_L")
        If Not oExtrude Is Nothing Then
            oExtrude.Definition.SetDistanceExtent(oDistance, kNegativeExtentDirection)
        Else
           MessageBox.Show( "Extrude feature 'RIP_L' not found.", "Title")

        End If
    Else
       MessageBox.Show("Component definition not found.", "Title")
 
    End If
End Sub

 

This code works for me.  Thanks, @Curtis_Waguespack 

0 Likes