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: 

iLogic - model or reference parameter

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
fsanchou
3634 Views, 14 Replies

iLogic - model or reference parameter

Hi,

 

I wish I perform the following code with iLogic.
Is it possible to change a model parameter to a reference parameter?

 

If My_Expression Then

' My dimension "d0" is a Driven Dimension
' or
' My dimension "d0" is a Reference Parameter

Else

' My dimension "d0" is NOT a Driven Dimension
' or
' My dimension "d0" is a Model Parameter

End If

 

Thanks,

14 REPLIES 14
Message 2 of 15

Hi fsanchou,

 

Here are a couple of examples. The first one gets input from the user:

 

MyQuestion = MessageBox.Show("Should d0 be Driven? ", "iLogic", MessageBoxButtons.YesNo)

'get the sketch to work with
oSketch = ThisDoc.Document.ComponentDefinition.Sketches.Item("Sketch1")

If MyQuestion = vbYes Then
oSketch.DimensionConstraints.Item(d0).Driven = True 
Else
oSketch.DimensionConstraints.Item(d0).Driven = False
End If

 This one simply toggles the driven state:

 

'get the sketch to work with
oSketch = ThisDoc.Document.ComponentDefinition.Sketches.Item("Sketch1")
'toggle from/to driven/driving
If oSketch.DimensionConstraints.Item(d0).Driven = True Then
oSketch.DimensionConstraints.Item(d0).Driven = False
Else
oSketch.DimensionConstraints.Item(d0).Driven = True
End If

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

Message 3 of 15

Curtis,

 

Thank you, this solves exactly my problem.

 

You are still effective,

Message 4 of 15

Curtis,

 

I answered a little too quickly without testing your code.

I tried the following code:

 

ThisDoc.Document.ComponentDefinition.Sketches.Item("Sketch1").DimensionConstraints.Item("d0").Driven = True

 

 

I get the following error:

 

 

System.Runtime.InteropServices.COMException (0x80020005): Le type ne correspond pas. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
   at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

In the API Help I found this information :

 

DimensionConstraints.Item( IndexAs Long ) As DimensionConstraint

NameDescription
IndexInput Long value that specifies the index of the object to return.

 

I have not found how to find the dimension's index.

 

Do you have a further response ?

Thanks

Message 5 of 15

Hi  fsanchou,

If you remove your dimension name from the quotes does it work then?

 

You have this:

 

ThisDoc.Document.ComponentDefinition.Sketches.Item("Sketch1").DimensionConstraints.Item("d0").Driven = True

I think you want this:

 

ThisDoc.Document.ComponentDefinition.Sketches.Item("Sketch1").DimensionConstraints.Item(d0).Driven = True

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

 

 

Message 6 of 15

Hi Curtis,

 

Thanks for your help,

I also tested this solution but it does not work.

 

d0 return the value of parameter

"d0" is a string

 

I think I need to find the ID (as long) of the dimension ...

 

Best regards,

Message 7 of 15

Hi  fsanchou,

 

Maybe I'm still not understanding what you're attempting to do.

 

The previous examples will change d0 to a driven dimension regardless of what the value of that dimension is. Are you needing to know or change the value of d0 also?

 

I guess I'm not sure why we need the index number when we already know the name of the parameter. Is the name likely to change?, or are you changing it programmatically?

 

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

Message 8 of 15

Hi Curtis,

 

I am looking to do exactly this code:

'get the sketch to work with
oSketch = ThisDoc.Document.ComponentDefinition.Sketches.Item("Sketch1")

'toggle from/to driven/driving
If oSketch.DimensionConstraints.Item(d0).Driven = True Then
oSketch.DimensionConstraints.Item(d0).Driven = False
Else
oSketch.DimensionConstraints.Item(d0).Driven = True
End If

 To do that:

4.jpg

 

But I have this error:

3.jpg

 

Here the part1.ipt

 

Thanks for your help,

 

Message 9 of 15
fsanchou
in reply to: fsanchou

Hi everyone,

 

I found :

 

'get the sketch to work with
oSketch = ThisDoc.Document.ComponentDefinition.Sketches.Item("Sketch1")

'toggle from/to driven/driving
Dim i As Long
For i = 1 To oSketch.DimensionConstraints.Count 
	If oSketch.DimensionConstraints.Item(i).Parameter.Name = "d0" Then
		If oSketch.DimensionConstraints.Item(i).Driven = True Then
		oSketch.DimensionConstraints.Item(i).Driven = False
		Else
		oSketch.DimensionConstraints.Item(i).Driven = True
		End If
	End If
Next

 

Thanks Curtis,

Message 10 of 15
akosi
in reply to: fsanchou

hi,

 

this code can help me too.

 

so i copy and paste it but it giving me error

 

Rule Compile Errors in Rule0, in Part3

Error on Line 7 : End of statement expected.

 

i dont understand

Message 11 of 15
jdkriek
in reply to: akosi

akosi,

 

The last script posted works for me as well. 

 

Post a screenshot of your iLogic Rule.

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 12 of 15
akosi
in reply to: jdkriek

thanks for immediate response guys...

ive attached a screen shot

 

inventor 2011

\vault pro 2012

Message 13 of 15
LOONYLEN
in reply to: jdkriek

Was there ever an answer to the line 7 error?

I have a need for this code, but I'm getting the same error as above, "line 7".

Senior Designer/Cad Administrator
Inventor 2012, w/SP2
Vault Collaboration 2012
Dell Precision T3500, Intel Xeon CPU
W3680 @3.33GHz, 16.0 GB of RAM
Microsoft Windows 7 Pro, 64 Bit Edition
Version 2009, w/SP1
Message 14 of 15
GosponZ
in reply to: LOONYLEN

Rule is working good.

Check parameter to match and sketch# to match. No problem here

Message 15 of 15
tim.mulder
in reply to: akosi

Hi akosi,

You probably have already figured this out considering how long ago this post was.

But for your information this used to catch me out alot when copying & pasting ilogic code (Please see below)

Untitled.jpg

Firstly as already mentioned make sure your sketch name matches the sketch you are querying.

Secondly always make sure you re-type the API words (purple words) when copying & pasting sometimes these words don't link/interface with the code.

Hope this helps for any future code writing

Kind Regards

Tim

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

Post to forums  

Autodesk Design & Make Report