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: 

Create user parameter values with iLogic

20 REPLIES 20
SOLVED
Reply
Message 1 of 21
karthur1
7523 Views, 20 Replies

Create user parameter values with iLogic

Curtis W. has this macro for writing the sheetmetal Extents width and length to the custom properties.  I need to get these values into the part parameters so that they can be used in the BOM.

 

I can get this to work if I manually create the "SM_Length" user parameter, but how do I make the iLogic CREATE the parameters if they do not already exist?  I think it would be something added below the "Catch..." just cant seem to figure out what it needs to be.

'look for custom iproperty and try to set it
Try
iProperties.Value("Custom", sExtLength)=Round(SheetMetal.FlatExtentsLength, iRoundValue)
Parameter("SM_Length")=Round(SheetMetal.FlatExtentsLength,4)

Catch
' assume error means not found and create it
customPropertySet.Add(Round(SheetMetal.FlatExtentsLength,iRoundValue), sExtLength)
EndTry

20 REPLIES 20
Message 2 of 21

Hi karthur1,

 

First, I applogize for not seeing your original question on the other thread. As for your question, I'm not sure I understand the need to have the extents info added as a parameter, since the information already exists in the file. Can you explain the end goal here, so that we can understand where the parameter you propose creating needs to be used?

 

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

 

Message 3 of 21


@Curtis_Waguespack wrote:

 I'm not sure I understand the need to have the extents info added as a parameter, since the information already exists in the file....

 


Curtis,

When I start a new SM part, the information is not there. There is nothing in the UserParameters.  After I create a flatpattern, I want the SM_Width and SM_Length to be added with this ilogic code. 

 

If I manually add the user parameter SM_Length, the snippet that I posted above will update the parameter.  I just can't figure out how to get it to create the user parameter if it is not there already.

 

The end result is I will use the exported SM_Length (and SM_Width) parameters in a custom expression that is displayed in the parts list for the SM part.  Something like this:

 

2012-10-29_1219.png

 

We are currently using the SM_Extents add-in that was written by Brian Ekins.  It has worked well, but we are now having trouble with it and I want something that I have more control over.

 

Thanks

 

Kirk A.

Windows 7 x64 -12 GB Ram
@intel i7-930 @ 3.60ghz
nVidia GTS 250 -1GB (Driver 301.42)
INV Pro R2013, SP1.1
Vault 2013

 

Message 4 of 21

Hi karthur1,

 

I think this will work for you, if not post back and I'll have another look. If it does workyou might update the original thread with a link to this one for people in future as well.

 

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

 

 

Imports  Inventor.UnitsTypeEnum
        
Dim oParams As Parameters
oParams=ThisDoc.Document.ComponentDefinition.Parameters
                
Dim oUserParams As UserParameters
oUserParams=oParams.UserParameters     

'look for user parameter and try to set it                
Try
oUserParams("SM_Length").Value = SheetMetal.FlatExtentsLength *2.54
Catch
' assume error means not found and create it
oUserParams.AddByValue("SM_Length", SheetMetal.FlatExtentsLength *2.54, kInchLengthUnits)
End Try

'ensure the parameters are exported/exposed as custom iProperties
Parameter.Param("Thickness").ExposedAsProperty = True
Parameter.Param("SM_Length").ExposedAsProperty = True
'set the description to read in the iProperties
iProperties.Value("Project", "Description") = "= SH <Thickness> x <SM_Length>"
'update the file
iLogicVb.UpdateWhenDone = True

 

Message 5 of 21

Modified it a little and got it exactly the way I want it.... Thanks.

 

One other Question:

 

How do I set the formatting of the exported user parameter with iLogic?  I would like the format to be fractional (1/16) with no units.

 

Like this:

 

2012-10-29_1533.png

Message 6 of 21

Hi karthur1,

 

I think this will do it. I didn't test it real well, so feel free to post back if you find an issue.

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

 

Imports  Inventor.UnitsTypeEnum
		
Dim oParams As Parameters
oParams=ThisDoc.Document.ComponentDefinition.Parameters
				
Dim oUserParams As UserParameters
oUserParams=oParams.UserParameters     

'look for user parameter and try to set it        		
Try
oUserParams("SM_Length").Value = SheetMetal.FlatExtentsLength *2.54
Catch
' assume error means not found and create it
oUserParams.AddByValue("SM_Length", SheetMetal.FlatExtentsLength *2.54, kInchLengthUnits) 
End Try

'create list of parameters to format
Dim myArrayList As New ArrayList
myArrayList.add("SM_Length")
myArrayList.add("Thickness")

Dim oString as Object
Dim oParam As Parameter
Dim oFormat As CustomPropertyFormat

i=0
For Each oString in myArrayList
myParam = myArrayList.Item(i)
oParam = oParams(myParam)
oParam.ExposedAsProperty = True
oFormat = oParams(myParam).CustomPropertyFormat
oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
oFormat.ShowUnitsString = True
oFormat.Units = "in"       
i= i+1
Next

'set the description to read in the iProperties
iProperties.Value("Project", "Description") = "= SH <Thickness> x <SM_Length>"
'update the file
iLogicVb.UpdateWhenDone = True

 

Message 7 of 21

Curtis,

One of the other sites I frequent has an animated smiley figure that bows down and pays homage. I think that is approperate here. Thank you so much for your willingness to spend time assisting us.

Jim

Inventor Premium 2013 SP1.1
Vault 2013- plain vanilla version
HP G71 notebook
celeron cpu w\ 4gb RAM and 64 bit system
Win 7 home premium

Ya, my boss has me running my personal machine at work.
Message 8 of 21
mnthailand
in reply to: karthur1

Format:HTML Format Version:1.0 StartHTML:     165 EndHTML:   11856 StartFragment:     314 EndFragment:   11824 StartSelection: 314 EndSelection:     314
SyntaxEditor Code Snippet

partDoc=ThisDoc.Document
Try
DimsheetMetalDefAsSheetMetalComponentDefinition=partDoc.ComponentDefinitionIf(sheetMetalDef.HasFlatPattern())ThenDimpropertySetAsPropertySetpropertySet=partDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")DimlengthPropertyAs [Property] DimwidthPropertyAs [Property] ForEachcustomPropertyAs [Property] InpropertySetIfcustomProperty.Name.Equals("FlatExtendsLength")lengthProperty=customPropertyElseIfcustomProperty.Name.Equals("FlatExtendsWidth")widthProperty=customPropertyEndIfNextIflengthPropertyIsNothingThenpropertySet.Add("empty", "FlatExtendsLength")EndIfIfwidthPropertyIsNothingThenpropertySet.Add("empty", "FlatExtendsWidth")EndIfiProperties.Value("Custom", "FlatExtendsLength")=Round(SheetMetal.FlatExtentsLength,2)iProperties.Value("Custom", "FlatExtendsWidth")=Round(SheetMetal.FlatExtentsWidth,2)
EndIfCatch
EndTry
Inventor 2011 (x64)
Productstream Professional 2011 (x64)
Windows 7 (x64)

Product design suite Professional 2013
Message 9 of 21

Curtis,

I added the last code into a new ilogic rule.  I get the following errors.  I tried to fix them, but didnt get very far with that.Smiley Sad

 

Thanks

 

2012-10-30_0712.png

Message 10 of 21

Hi karthur1,

 

From the screen grab, it looks like there might be some extra returns or characters caused by copy/paste formatting issues. Attached is the same rule, in a *.txt file. I think if you copy and paste from this file you'll get it to work.

 

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

 

 

 

 

 

Message 11 of 21

Hi JimSteinmeyer,

 

Thanks for the kind words. Smiley Happy

 

I've picked up a lot of information, tip, tricks, etc. from other users on this forum, so I'm happy to contribute something in return.

 

Curtis
http://inventortrenches.blogspot.com

 

 

Message 12 of 21

Curtis,

The last code you posted worked fine.  I was needing to add a couple more User Parameters and I thought I could just add it to what you had and I could learn something along the way. 

 

I've attached what I have so far.  Could you please look at it and tell me/show me what I am doing wrong.  When the code runs I get an error.

 

Basically, I have added the two parameters, "SheetMetalWidth" and Cutlength" and I am wanting these formatted the same as the "SheetMetalLength".

 

Thanks,

Kirk

Message 13 of 21

Hi karthur1,

 

Attached is a *.txt file with the updated code. I've embeded it here as well (it helps with searches in the future). Basically, what I've done is create an array list of the parameters to be formatted. The formatting is applied to any of the parameters that are added to the array list.

 

So in the future should you need to update this and add a parameter, you can just add another Try/Catch for the new parameter, just as you did, and then add the new parameter to the ArrayList.

 

This approach formats all of the parameters in the list the same, which might not be what you want. If not the arraylist might not be the way to go.

 

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

 

Imports  Inventor.UnitsTypeEnum
Dim oParams As Parameters
oParams=ThisDoc.Document.ComponentDefinition.Parameters
Dim oUserParams As UserParameters
oUserParams=oParams.UserParameters     

'look for user parameter SheetMetalLength and try to set it        		
Try
oUserParams("SheetMetalLength").Value = SheetMetal.FlatExtentsLength *2.54
Catch
' assume error means not found and create it
oUserParams.AddByValue("SheetMetalLength", SheetMetal.FlatExtentsLength *2.54, kInchLengthUnits) 
End Try

'look for user parameter SheetMetalWidth and try to set it        		
Try
oUserParams("SheetMetalWidth").Value = SheetMetal.FlatExtentsWidth *2.54
Catch
' assume error means not found and create it
oUserParams.AddByValue("SheetMetalWidth", SheetMetal.FlatExtentsWidth *2.54, kInchLengthUnits) 
End Try

'look for user parameter Cutlength hand try to set it        		
Try
oUserParams("Cutlength").Value = SheetMetal.FlatExtentsLength *2.54
Catch
' assume error means not found and create it
oUserParams.AddByValue("Cutlength", SheetMetal.FlatExtentsLength *2.54, kInchLengthUnits) 
End Try

'create list of parameters to format
'add more if needed
Dim myArrayList As New ArrayList
myArrayList.add("SM_Length")
myArrayList.add("SheetMetalLength")
myArrayList.add("Cutlength")
myArrayList.add("Thickness")

Dim oString as Object
Dim oParam As Parameter
Dim oFormat As CustomPropertyFormat

'set the list item number to start at zero
i=0
'step through the parameter list (myArrayList)
'and format each member of the list
For Each oString in myArrayList
myParam = myArrayList.Item(i)
oParam = oParams(myParam)
oParam.ExposedAsProperty = True
oFormat = oParams(myParam).CustomPropertyFormat
oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
oFormat.ShowUnitsString = False
'increment the list item number by 1
i= i+1
Next

'set the description to read in the iProperties
'iProperties.Value("Project", "Description") = "= SH <Thickness> x <SM_Length>"
'update the file
iLogicVb.UpdateWhenDone = True

 

Message 14 of 21

SWEET!

 

I am going to update my Sheetmetal template to use this external rule and trigger it to run on Part Geometry Changes. That way all future sheetmetal parts will run this rule.  No problem here.

 

My concern now  is that I am wanting to uninstall the SheetMetalExtents add-in that I have running.  My concerns is that since my other Inventor users are used to this happening automatically when they change the part, the existing parameters will not update correctly (unless they add the trigger in an existing SM part).

 

Any suggestions on how to handle this?

 

 

Message 15 of 21


@karthur1 wrote:

Any suggestions on how to handle this?

 


Hi karthur1,

 

There is a gentleman on these forums that goes by the handle MegaJerk. He has written a tool called the Code Injector.

http://beinginventive.typepad.com/being-inventive/2012/02/injecting-ilogic-code-and-ilogic-event-tri...

 

Updated Version:

http://beinginventive.typepad.com/being-inventive/2012/08/major-upgrade-to-the-ilogic-code-injector-...

 

 

 

I think I would create this sheet metal rule as an External ilogic rule (for instance named "Sheet Metal Extents Rule"). Then I'd use the Code Injector tool to batch process existing files to inject the following line, and have it run on the Before Save Event trigger:

 

iLogicVb.RunExternalRule("Sheet Metal Extents Rule")

 

You could then insert this line into your sheet metal file template (to run on the save event) to handle all new sheet metal files going forward. Keepin the sheet metal rule external to the files, allows you to make updates to it, without having to go back and update each file.

 

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

 

 

 

 

Message 16 of 21

I just noticed an error in the last code I posted when creating the array list:

 

I had this:

 

'create list of parameters to format 
'add more if needed
Dim myArrayList As New ArrayList
myArrayList.add("SM_Length")
myArrayList.add("SheetMetalLength")
myArrayList.add("Cutlength")
myArrayList.add("Thickness")

 It should have been this:

 

		
'create list of parameters to format
'add more if needed
Dim myArrayList As New ArrayList
myArrayList.add("SheetMetalWidth")
myArrayList.add("SheetMetalLength")
myArrayList.add("Cutlength")
myArrayList.add("Thickness")

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

Message 17 of 21

I'm trying to come up with a way I can isolate just the sheetmetal part files from my other ipt files. I would need to inject the code in just those files.  If I don't do that and I run the code injector tool on ALL my ipts, the non-sheetmetal parts will have an error when they are later saved.

 

Another question about the code.... If the flat pattern does not exist and I save the SM part, I get an error. My guess that is because the SheetMetal.FlatExtentsLength does not exist.  Can something be added that will exit the routine if the flatpattern does not exist?

 

Kirk

Message 18 of 21

Hi karthur1,

 

In the rule found in the original rule you'll find some lines of code that check that the file is a sheet metal part, and that it has a flat pattern created.

 

 

 

'make sure the part is a sheet metal part
If oDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 
MessageBox.Show("This is not a sheet metal part.", "iLogic")
Return 'exit rule
Else 

Dim oSMDef As SheetMetalComponentDefinition
oSMDef = oDoc.ComponentDefinition

'check for flat pattern
If oSMDef.FlatPattern Is Nothing Then 
'create a flat pattern if it doesn't exist
oSMDef.Unfold
oSMDef.FlatPattern.ExitEdit
Else

 

You could add these to the top of the rule, or create a seperate "check" rule that is run first.

 

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

 

 

Message 19 of 21
RobJV
in reply to: Curtis_Waguespack

I use Brian Ekins addin on a daily basis and have noticed a need for additional "rebuild alls" in 2013 which I am working through. 

 

Unless I am missing something (which I probably am), the one major problem with this ilogic code is that it will not work on legacy sheetmetal parts.  If it is triggered by the sheetmetal template, what happens to all previously created sheetmetal parts that you update or change?  Will they not all be incorrect and reflect wrong information in the partslists?  This is also the major problem with using the built in Inventor parameters for the sheet metal extents - you can add them to the template file but they are useless for all your legacy data. (Which is why the Ekins addin has been awesome although like karthur, I have been experiencing a need for additional rebuild commands in 2013.)

 

Curtis, maybe you can correct me or possibly I don't fully understand the trigger for this ilogic code?

 

Thanks!

 

 

Message 20 of 21

Curtis,

I just found this worked great for 2014! I tried to change the line

oFormat.Units = "in"  to

oFormat.Units = "ft"  to make my BOM"s see the dims in feet and inches. It worked ok but now i get a error....

 

Error in rule: SMetal_Extents, in document: sheetmetalexte345nts.ipt
Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.CustomPropertyFormat.set_ShowUnitsString(Boolean )
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

 

again everything works correctly but the error pops up and i just close it. I would like to know how to I may change anything else to prevent the error.

 

The help is greatly appreciated!

 

 

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

Post to forums  

Autodesk Design & Make Report