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,
Solved! Go to Solution.
Solved by fsanchou. Go to Solution.
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
Curtis,
Thank you, this solves exactly my problem.
You are still effective,
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
Name | Description |
Index | Input 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
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
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,
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
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:
But I have this error:
Here the part1.ipt
Thanks for your help,
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,
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
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".
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)
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