Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic for various purposes

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
346 Views, 4 Replies

iLogic for various purposes

Hi. I have written an iLogic rule that is supposed to first update the model and mass properties. It will then define three parameters (Wid, Len and kFac). Subsequently it will use Wid and Len to write a string and define kFac as the kfactor only if sheet metal is active. However when I run this script, it gives the following error (only in Swedish not in English) "Det går inte att hitta en matchande överlagring eftersom ingen tillgänglig parametro accepterar det här antalet argument." (It is not possible to find a matching overlay because no available parametro accepts this number of arguments.). What is wrong in the code?

 

Sub Main()
Dim PartDoc As PartDocument = ThisDoc.Document
Dim userParams As UserParameters = PartDoc.ComponentDefinition.Parameters.UserParameters
'Mass properties
ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute
myMass = iProperties.Mass
iLogicVb.UpdateWhenDone = True
parametro = ThisApplication.ActiveDocument.ComponentDefinition.Parameters("Wid")
Dim newParamW As UserParameter = userParams.AddByExpression("Wid", 0, "mm")
parametro = ThisApplication.ActiveDocument.ComponentDefinition.Parameters("Len")
Dim newParamL As UserParameter = userParams.AddByExpression("Len", 0, "mm")
parametro = ThisApplication.ActiveDocument.ComponentDefinition.Parameters("kFac")
Dim newParamK As UserParameter = userParams.AddByExpression("kFac", 0, "mm")
	newParamK.ExposedAsProperty = True
	Dim cFormat As CustomPropertyFormat = newParamK.CustomPropertyFormat
	cFormat.PropertyType = CustomPropertyTypeEnum.kTextPropertyType
	cFormat.Precision = CustomPropertyPrecisionEnum.kThirtySecondsFractionalLengthPrecision
	cFormat.ShowTrailingZeros = True
	cFormat.ShowUnitsString = False
End Sub

'Material dimension
Function parametro(Wid, Len)
	If SheetMetal.FlatExtentsArea>0 Then
		Wid = Ceil(SheetMetal.FlatExtentsWidth)
		Len = Ceil(SheetMetal.FlatExtentsLength)
		If Wid = Len Then
			iProperties.Value("Custom", "Material dimension") = "□" & Wid & ", t = " & Thickness
		Else 
			iProperties.Value("Custom", "Material dimension") = Wid & " x " & Len & ", t = " & Thickness
		End If
	End If
End Function

'K-Factor
Function parametro(kfac)
If SheetMetal.FlatExtentsArea>0 Then
kFac = SheetMetal.ActiveKFactor
End If
End Function

 

Thanks in advance 

Tags (1)
4 REPLIES 4
Message 2 of 5
Sergio.D.Suárez
in reply to: Anonymous

The first error visible at first glance, if kFac represents the factor k, keep in mind that its unit is "ul" (actually it means without units of measure because it is a constant).

Try to modify this and then tell us what error is triggered so we can help you, regards

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 5
Anonymous
in reply to: Sergio.D.Suárez

The fault lies in line 8 

parametro = ThisApplication.ActiveDocument.ComponentDefinition.Parameters("Wid")

line 10

parametro = ThisApplication.ActiveDocument.ComponentDefinition.Parameters("Len")

and line 12 

parametro = ThisApplication.ActiveDocument.ComponentDefinition.Parameters("kFac")
Message 4 of 5
Sergio.D.Suárez
in reply to: Anonymous

Hi, accommodate what I think you are trying to do.
I recommend that you work with subroutines, it's what works for me, I can cut and paste blocks that work because I can test them separately, if you use a function, use it only when you want to return a value to the submain for example.
First update the mass as you adjusted, then delete the existing variables (just in case they are wrong)
then it is updating parameters.

If you have a previous flattening eliminate it to avoid problems

Sub Main()
	'On Error Resume Next
Dim PartDoc As PartDocument = ThisDoc.Document
Dim userParams As UserParameters = PartDoc.ComponentDefinition.Parameters.UserParameters
'Mass properties
ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute2(True)
myMass = iProperties.Mass
iLogicVb.UpdateWhenDone = True


	Delete_Variables

	Check_Wid

	Check_Len
	
	Check_kFac
	
	parametro1
	
	parametro2
	
Parameter.UpdateAfterChange = True
iLogicVb.UpdateWhenDone = True
	
End Sub


Sub Delete_Variables()
On Error Resume Next
Dim p1 As Parameter 
Dim p2 As Parameter 
Dim p3 As Parameter 

p1 = ThisDoc.Document.ComponentDefinition.Parameters.Item("Wid") 
p2 = ThisDoc.Document.ComponentDefinition.Parameters.Item("Len")
p3 = ThisDoc.Document.ComponentDefinition.Parameters.Item("kFac") 

End Sub

Sub Check_Wid
Try
	Dim a1 As Parameter
	a1 = ThisDoc.Document.ComponentDefinition.Parameters.Item("Wid") 
Catch
	Dim a1 As Parameters
	a1 = ThisDoc.Document.ComponentDefinition.Parameters
	a1.UserParameters.AddByExpression("Wid","20","mm")
	oA1 = Parameter.Param("Wid")
	oA1.ExposedAsProperty = True
	oFA1=oA1.CustomPropertyFormat
	oFA1.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
	oFA1.Precision=Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
	oFA1.ShowUnitsString=False
	oFA1.ShowTrailingZeros = False
	oFA1.ShowLeadingZeros = False
End Try
	
End Sub

Sub Check_Len
Try
	Dim a1 As Parameter
	a1 = ThisDoc.Document.ComponentDefinition.Parameters.Item("Len") 
Catch
	Dim a1 As Parameters
	a1 = ThisDoc.Document.ComponentDefinition.Parameters
	a1.UserParameters.AddByExpression("Len","30","mm")
	oA1 = Parameter.Param("Len")
	oA1.ExposedAsProperty = True
	oFA1=oA1.CustomPropertyFormat
	oFA1.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
	oFA1.Precision=Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
	oFA1.ShowUnitsString=False
	oFA1.ShowTrailingZeros = False
	oFA1.ShowLeadingZeros = False
End Try
	
End Sub

Sub Check_kFac
Try
	Dim a1 As Parameter
	a1 = ThisDoc.Document.ComponentDefinition.Parameters.Item("kFac") 
Catch
	Dim a1 As Parameters
	a1 = ThisDoc.Document.ComponentDefinition.Parameters
	a1.UserParameters.AddByExpression("kFac","0.33","ul")
	oA1 = Parameter.Param("kFac")
	oA1.ExposedAsProperty = True
	oFA1=oA1.CustomPropertyFormat
	oFA1.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
	oFA1.Precision=Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
	oFA1.ShowUnitsString=False
	oFA1.ShowTrailingZeros = False
	oFA1.ShowLeadingZeros = False
End Try
	
End Sub

'Material dimension
Sub parametro1
	
Dim oWid As Parameter
oWid = ThisDoc.Document.ComponentDefinition.Parameters.Item("Wid") 
Dim oLen As Parameter
oLen = ThisDoc.Document.ComponentDefinition.Parameters.Item("Len") 
	
	
	If SheetMetal.FlatExtentsArea>0 Then
		oWid.Value = Ceil(SheetMetal.FlatExtentsWidth)
		oLen.Value = Ceil(SheetMetal.FlatExtentsLength)
		If oWid.Value = oLen.Value Then
			iProperties.Value("Custom", "Material dimension") = "□" & oWid.Value & ", t = " & Thickness
		Else 
			iProperties.Value("Custom", "Material dimension") = oWid.Value & " x " & oLen.Value & ", t = " & Thickness
		End If
	End If
End Sub

'K-Factor
Sub parametro2
	
Dim okFac As Parameter
okFac = ThisDoc.Document.ComponentDefinition.Parameters.Item("kFac") 
	
If SheetMetal.FlatExtentsArea>0 Then
okFac.Value = SheetMetal.ActiveKFactor
End If
End Sub

 I hope you find it useful, greetings


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 5 of 5
Anonymous
in reply to: Sergio.D.Suárez

Works perfectly. Thanks very much!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report