iLogic - model or reference parameter

iLogic - model or reference parameter

fsanchou
Advocate Advocate
4,354 Views
14 Replies
Message 1 of 15

iLogic - model or reference parameter

fsanchou
Advocate
Advocate

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,

0 Likes
Accepted solutions (1)
4,355 Views
14 Replies
Replies (14)
Message 2 of 15

Curtis_Waguespack
Consultant
Consultant

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

EESignature

Message 3 of 15

fsanchou
Advocate
Advocate

Curtis,

 

Thank you, this solves exactly my problem.

 

You are still effective,

0 Likes
Message 4 of 15

fsanchou
Advocate
Advocate

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

0 Likes
Message 5 of 15

Curtis_Waguespack
Consultant
Consultant

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

 

 

EESignature

0 Likes
Message 6 of 15

fsanchou
Advocate
Advocate

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,

0 Likes
Message 7 of 15

Curtis_Waguespack
Consultant
Consultant

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

EESignature

0 Likes
Message 8 of 15

fsanchou
Advocate
Advocate

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,

 

0 Likes
Message 9 of 15

fsanchou
Advocate
Advocate
Accepted solution

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,

0 Likes
Message 10 of 15

Anonymous
Not applicable

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

0 Likes
Message 11 of 15

jdkriek
Advisor
Advisor

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.


0 Likes
Message 12 of 15

Anonymous
Not applicable

thanks for immediate response guys...

ive attached a screen shot

 

inventor 2011

\vault pro 2012

0 Likes
Message 13 of 15

Anonymous
Not applicable

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".

0 Likes
Message 14 of 15

GosponZ
Collaborator
Collaborator

Rule is working good.

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

0 Likes
Message 15 of 15

Anonymous
Not applicable

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

0 Likes