Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Use ilogic to set the size and length of a part

25 REPLIES 25
SOLVED
Reply
Message 1 of 26
amasva
3788 Views, 25 Replies

Use ilogic to set the size and length of a part

Hi

 

I have created a ilogic rule that should set the size and the cut length of my parts. Most of the time the rule behave as I want it to. But sometime it gives me a error. See attached picture. It would be great if anyone could tell me what is wrong with the rule.. By the way, I have included this rule in my custom content center parts (beam's etc). The rule is:


'Turn off workfeatures
ThisDoc.Document.ObjectVisibility.AllWorkFeatures = False

'check if the part has any geometry
If Measure.ExtentsLength="0" Then

'sets values to 0 if no geometry exists
iProperties.Value("Custom", "G_L")="0"
iProperties.Value("Custom", "Size")="0,0,0"

'Turn on workfeatures
ThisDoc.Document.ObjectVisibility.AllWorkFeatures = True

Return

End If

'Sets size of part
iProperties.Value("Custom", "Size")=Round(Measure.ExtentsLength, 1) & "mmX" & Round(Measure.ExtentsWidth, 1) & "mmX" & Round(Measure.ExtentsHeight, 1) &"mm"

 

'Sets a value in the properties field G_L (cutlenght) based on what value that is written in the filed "kpl" (x,y or z)
If iProperties.Value("Custom", "kpl")="Z" Then
iProperties.Value("Custom", "G_L")=Round(Measure.ExtentsHeight, 0) & "mm"
Else If iProperties.Value("Custom", "kpl")="z" Then
iProperties.Value("Custom", "G_L")=Round(Measure.ExtentsHeight, 0) & "mm"
Else If iProperties.Value("Custom", "kpl")="X" Then
iProperties.Value("Custom", "G_L")=Round(Measure.ExtentsLength, 0) & "mm"
Else If iProperties.Value("Custom", "kpl")="x" Then
iProperties.Value("Custom", "G_L")=Round(Measure.ExtentsLength, 0) & "mm"
Else If iProperties.Value("Custom", "kpl")="Y" Then
iProperties.Value("Custom", "G_L")=Round(Measure.ExtentsWidth, 0) & "mm"
Else If iProperties.Value("Custom", "kpl")="y" Then
iProperties.Value("Custom", "G_L")=Round(Measure.ExtentsWidth, 0) & "mm"
Else iProperties.Value("Custom", "G_L")=iProperties.Value("Custom", "kpl")
End If

'Turn on workfeatures
ThisDoc.Document.ObjectVisibility.AllWorkFeatures = True

 

 

 

 

Asle Martin Svastuen
Autodesk Product Design Suite Ulitmate 2012 Sp1 / Vault Collaboration 2012 Sp1
HP EliteBook 8560w
Intel(R)Core(TM) i7 CPU Q 720 @ 2,0GHz 2,0GHz
16GB RAM
Windows 7 X64 SP1
25 REPLIES 25
Message 2 of 26
Jon.Dean
in reply to: amasva

Is this problem now solved or do you still need some help?



Jon Dean

Message 3 of 26
amasva
in reply to: amasva

Hi. This is still a problem and I would appreciate some help 🙂 The problem seems to be the lines where I turn off and on the workfeatures..
Asle Martin Svastuen
Autodesk Product Design Suite Ulitmate 2012 Sp1 / Vault Collaboration 2012 Sp1
HP EliteBook 8560w
Intel(R)Core(TM) i7 CPU Q 720 @ 2,0GHz 2,0GHz
16GB RAM
Windows 7 X64 SP1
Message 4 of 26
Jon.Dean
in reply to: amasva

How do you know there will be a Custom Variable "kpl". You don't give it an initial value.

Have you declared this variable in your Template file?



Jon Dean

Message 5 of 26
amasva
in reply to: amasva

This rule is started by a main rule. The main rule create the custom propery "kpl" and several other properties. So the property "kpl" will always exist when this rule runs 🙂
Asle Martin Svastuen
Autodesk Product Design Suite Ulitmate 2012 Sp1 / Vault Collaboration 2012 Sp1
HP EliteBook 8560w
Intel(R)Core(TM) i7 CPU Q 720 @ 2,0GHz 2,0GHz
16GB RAM
Windows 7 X64 SP1
Message 6 of 26
Jon.Dean
in reply to: amasva

Take a look at the following Blog entry, it may be related to your problem.

 

Length parameter of Frame generator beams.

 

Jon



Jon Dean

Message 7 of 26
MjDeck
in reply to: Jon.Dean

Asle,
 What is the error message?  If the error has a More Info tab, please click on that.  Then copy and paste the text and post it here as text.  That is better than posting a screenshot.


Mike Deck
Software Developer
Autodesk, Inc.

Message 8 of 26
amasva
in reply to: MjDeck

Hi

 

The error message is:

Error in rule: Sette_yttermål, in document: Sette_yttermål.iLogicVb

Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))

 

And under More Info is:

 

System.Runtime.InteropServices.COMException (0x80020003): Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))

at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)

at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)

at LmiRuleScript.Main()

at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)

at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Thanks for checking in to this 🙂

 

Asle Martin Svastuen
Autodesk Product Design Suite Ulitmate 2012 Sp1 / Vault Collaboration 2012 Sp1
HP EliteBook 8560w
Intel(R)Core(TM) i7 CPU Q 720 @ 2,0GHz 2,0GHz
16GB RAM
Windows 7 X64 SP1
Message 9 of 26
MjDeck
in reply to: amasva

I'm not sure what's causing the problem.  Here's a few more questions:
How are you running the external rule? Do you run it manually, or automatically on an event?
Do you ever run it in a drawing document?  That will produce this error.

Can you try to comment out all the lines that have this text:

ThisDoc.Document.ObjectVisibility.AllWorkFeatures

and see if that makes the error message go away?


Mike Deck
Software Developer
Autodesk, Inc.

Message 10 of 26
amasva
in reply to: amasva

If I comment out the line the rule runs fine. The rule is set to run on the event "before save" i our custom conter center parts. (the event is set in the conter center templates).
Asle Martin Svastuen
Autodesk Product Design Suite Ulitmate 2012 Sp1 / Vault Collaboration 2012 Sp1
HP EliteBook 8560w
Intel(R)Core(TM) i7 CPU Q 720 @ 2,0GHz 2,0GHz
16GB RAM
Windows 7 X64 SP1
Message 11 of 26
MjDeck
in reply to: amasva

Does the error message seem to happen at random?   How often does it happen?
Does it happen only in certain parts?
Do you have only one solid body in the part?  If so, I can send you code that gets the extents of the solid body only.  Then you won't need the  ThisDoc.Document.ObjectVisibility.AllWorkFeatures statement.
(I can also provide code to work on more than one solid body, but it would be more complex.)


Mike Deck
Software Developer
Autodesk, Inc.

Message 12 of 26
amasva
in reply to: amasva

It seems to happen after placing a content center part and then chosing change size. But it has also happen random. All parts has only one body so if you could share that rule it would be greate 🙂
Asle Martin Svastuen
Autodesk Product Design Suite Ulitmate 2012 Sp1 / Vault Collaboration 2012 Sp1
HP EliteBook 8560w
Intel(R)Core(TM) i7 CPU Q 720 @ 2,0GHz 2,0GHz
16GB RAM
Windows 7 X64 SP1
Message 13 of 26
MjDeck
in reply to: amasva

Please try the attached rule.  It is a modified version of your original rule, with code added to replace the Measure.Extents functions.


Mike Deck
Software Developer
Autodesk, Inc.

Message 14 of 26
amasva
in reply to: amasva

Thanks, I will try this rule first thing monday morning 🙂
Asle Martin Svastuen
Autodesk Product Design Suite Ulitmate 2012 Sp1 / Vault Collaboration 2012 Sp1
HP EliteBook 8560w
Intel(R)Core(TM) i7 CPU Q 720 @ 2,0GHz 2,0GHz
16GB RAM
Windows 7 X64 SP1
Message 15 of 26
amasva
in reply to: MjDeck

This rule seems to work. Thanks a lot 🙂

Asle Martin Svastuen
Autodesk Product Design Suite Ulitmate 2012 Sp1 / Vault Collaboration 2012 Sp1
HP EliteBook 8560w
Intel(R)Core(TM) i7 CPU Q 720 @ 2,0GHz 2,0GHz
16GB RAM
Windows 7 X64 SP1
Message 16 of 26
amasva
in reply to: MjDeck

A update on this issue. The problem seems to occur when I (from a assembly) edit a part, return (without saving) and hit save. If the part is in a subassembly and I returns to the top level assembly before saving the odds for the error to occur are rising..

Asle Martin Svastuen
Autodesk Product Design Suite Ulitmate 2012 Sp1 / Vault Collaboration 2012 Sp1
HP EliteBook 8560w
Intel(R)Core(TM) i7 CPU Q 720 @ 2,0GHz 2,0GHz
16GB RAM
Windows 7 X64 SP1
Message 17 of 26
MjDeck
in reply to: amasva

Can you post yoir model (all assemblies and parts)?  That would probably help me to figure out what is causing the problem.


Mike Deck
Software Developer
Autodesk, Inc.

Message 18 of 26
amasva
in reply to: MjDeck

Hi

 

Attached is a zip folder that contains one part and two assemblies. It also contain the rules that is trigged by the part. This is external rules. The "main" rule is "IPT_KJORE_FOR_LAGRE.iLogicVb". This rule is set to run "before save" in all new ipt files. This rule is starting the other rules. (I'm from Norway so you must excuse me for the Norwegian language in the rules 🙂 )

 

The top level assembly is "Assembly4.iam".

 

A video where I get the error is to be found on youtube: http://www.youtube.com/watch?v=7raaXpXfcPQ

 

Asle Svastuen

Asle Martin Svastuen
Autodesk Product Design Suite Ulitmate 2012 Sp1 / Vault Collaboration 2012 Sp1
HP EliteBook 8560w
Intel(R)Core(TM) i7 CPU Q 720 @ 2,0GHz 2,0GHz
16GB RAM
Windows 7 X64 SP1
Message 19 of 26
MjDeck
in reply to: amasva

Asle,

 I wasn't able to reproduce the problem, but I have an idea that might fix it.  Please try this modified version of your Sette_kapplengde_G_L.iLogicVb external rule.  The change I made was to explicitly use a PartDocument instead of a Document.

If this doesn't fix the problem, can you post a few more files?  You didn't include IAM_KJORE_FOR_LAGRE.iLogicVb.  Also, are you creating new parts from templates that contain rules?  If so, please post your templates.

Although your signature says Inventor 2011, I see that you are using 2012.  Do you have SP1 installed?


Mike Deck
Software Developer
Autodesk, Inc.

Message 20 of 26
amasva
in reply to: MjDeck

I thought I was strange that you was not able to reproduce the error, then I open the assembly an found out that neither was I. Then after some testing it seem that I had to create the part place it in the assembly and then place the assembly in a new assembly without exit Inventor. Then (out of nowhere) I got a new error. This error is similar to the old but refer to a new rule. This rule is similar to the rule that sets the size on a part, but it is used to set the size of a assembly. I'm starting to give up.. Attached is my template ipt, iam and all rules.

 

And my signature is updated 🙂

Asle Martin Svastuen
Autodesk Product Design Suite Ulitmate 2012 Sp1 / Vault Collaboration 2012 Sp1
HP EliteBook 8560w
Intel(R)Core(TM) i7 CPU Q 720 @ 2,0GHz 2,0GHz
16GB RAM
Windows 7 X64 SP1

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

Post to forums  

Autodesk Design & Make Report