Inventor General

Reply
*Expert Elite*
Curtis_Waguespack
Posts: 2,565
Registered: ‎03-08-2006
Message 11 of 20 (1,294 Views)

Re: Create user parameter values with iLogic

10-30-2012 06:45 AM in reply to: JimSteinmeyer

Hi JimSteinmeyer,

 

Thanks for the kind words. :smileyhappy:

 

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

 

 



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





*Expert Elite*
karthur1
Posts: 4,039
Registered: ‎04-27-2005
Message 12 of 20 (1,277 Views)

Re: Create user parameter values with iLogic

10-30-2012 10:26 AM in reply to: Curtis_Waguespack

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

*Expert Elite*
Curtis_Waguespack
Posts: 2,565
Registered: ‎03-08-2006
Message 13 of 20 (1,268 Views)

Re: Create user parameter values with iLogic

10-30-2012 11:58 AM in reply to: Curtis_Waguespack

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

 



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





*Expert Elite*
karthur1
Posts: 4,039
Registered: ‎04-27-2005
Message 14 of 20 (1,261 Views)

Re: Create user parameter values with iLogic

10-30-2012 12:45 PM in reply to: Curtis_Waguespack

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?

 

 

*Expert Elite*
Curtis_Waguespack
Posts: 2,565
Registered: ‎03-08-2006
Message 15 of 20 (1,247 Views)

Re: Create user parameter values with iLogic

10-30-2012 01:34 PM in reply to: karthur1

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

 

 

 

 



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





*Expert Elite*
Curtis_Waguespack
Posts: 2,565
Registered: ‎03-08-2006
Message 16 of 20 (1,240 Views)

Re: Create user parameter values with iLogic

10-30-2012 01:46 PM in reply to: Curtis_Waguespack

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



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





*Expert Elite*
karthur1
Posts: 4,039
Registered: ‎04-27-2005
Message 17 of 20 (1,218 Views)

Re: Create user parameter values with iLogic

10-31-2012 06:49 AM in reply to: Curtis_Waguespack

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

*Expert Elite*
Curtis_Waguespack
Posts: 2,565
Registered: ‎03-08-2006
Message 18 of 20 (1,207 Views)

Re: Create user parameter values with iLogic

10-31-2012 07:04 AM in reply to: Curtis_Waguespack

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

 

 



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





Mentor
Posts: 521
Registered: ‎07-14-2004
Message 19 of 20 (1,189 Views)

Re: Create user parameter values with iLogic

10-31-2012 09:35 AM 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!

 

 

Member
Posts: 5
Registered: ‎09-09-2013
Message 20 of 20 (208 Views)

Re: Create user parameter values with iLogic

03-06-2014 02:34 PM in reply to: Curtis_Waguespack

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!

 

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube