Hey everyone,
I'm having a problem with iLogic. In a part that I have I want a driven dimension so that I can stretch the part by hand. I want this driven dimension to have a minimal and a maximal value and an increment of 100mm. I also want the part to update automatically when I stretched the sketch. When I use this reference parameter in my iLogic code nothing happens.
I'm testing this with just a rectangle sketch with one driven dimension, a driving dimension and a extrude, just to keep things simple.
When I work with normal dimensions this all isn't a problem, but with a driven dimension I just can't get it to work. Googeling my problem doesn't give me the answer I'm looking for.
I found that when I used the statement where BaanLengte is the driven dimension:
If BaanLengte < 500 Then
MessageBox.Show("Te Klein, "Title")
BaanLengte = 500
End If
It shows the messagebox, but it doesnt change the BaanLengte parameter. So iLogic recognises the driven dimension but doesnt overwrite it with the value I want it to.
I hope someone here can help me, thanks in advance.
Robbert
Solved! Go to Solution.
Solved by mrattray. Go to Solution.
Hi Blokkie862,
Would it work to toggle the driven dimension to a driving dimension then change its value, then toggle it back? If so there is some example code for working with driven dimensions at this link:
Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Hey Curtis,
Thanks for your reply. I have tried the solution in the link you gave me, but I keep getting the error:
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
I have done some searching on Google where was said that I had to clean my Temporary ASP.NET Files, too bad that the temporary folders were all empty already.
The code I used from your link is this one:
ThisDoc.Document.ComponentDefinition.Sketches.Item("Sketch").DimensionConstraints.Item(d10).Driven= False
"Sketch" is the name I gave to the sketch where the dimension is found. d10 Is the parameter that needs to be changed. I have tried with and without quotations marks.
But isn't it possible to let iLogic overwrite an driven dimension? So the only way is to make it driving, change the value, change it back to driven?
Do you have any idea how to get it working? Thanks,
Robbert
Hey Mike,
Thanks for you're reply. I can change it by hand with the UI from Driven to Driving without constrained errors. So that means that it is possible with iLogic the way you described it? Turning off Driven, change the value, and then change it back to Driven?
Do you have any idea what the reason is that I get that error message? If so, do you have a solution to this problem? So that I can change the parameter from Driven to Driving and back with iLogic.
Thanks for cleaering up the fact that iLogic can't override Driven dimensions, I couldn't find that on the internet.
Robbert
Actually, I just spotted the problem. This is an easy one, assuming nothing else is wrong.
You posted that you used this line:
ThisDoc.Document.ComponentDefinition.Sketches.Item("Sketch").DimensionConstraints.Item(d10).Driven= False
You need to use quotation marks when you refer to something by its name. This is to differentiate between entered strings and varibale names. Like this:
ThisDoc.Document.ComponentDefinition.Sketches.Item("Sketch").DimensionConstraints.Item("d10").Driven= False
Hope this works for you!
Hey Mike,
Thanks for your quick reply again. It didn't solve the problem, keep getting the same error:
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
The sketch is very simple, it is just a rectangle with one Driving dimension, and one Driven dimension. So I can test if it works or not.
Any more idea's what the problem may be?
Robbert
Here is the file, I made a mistake with a sketch name in the code when I was trying your code, din't solve anything but it did change the error, sorry for that. Here is the error:
Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
I'm working in Inventor 2013 btw.
Robbert
There seems to be a problem with accessing "DimensionConstraint" via .Item using the name. I think because we're trying to use the name of the parameter instead of the name of the dimensional constraint. Anyways, I came up with this work around:
Option Explicit Sub Main iLogicVb.UpdateWhenDone = True Dim oSketch As Sketch Dim oDim As DimensionConstraint Dim oDims As DimensionConstraints Dim oParam As ModelParameter oSketch = ThisDoc.Document.ComponentDefinition.Sketches.Item("Sketch1") oDims = oSketch.DimensionConstraints For Each oDim In oDims If oDim.Driven = True Then Exit For Next oDim.Driven = False oParam = oDim.Parameter If oParam.Value < 20 Then oParam.Value = 20 ElseIf oParam.Value > 100 Then oParam.Value = 100 Else oParam.Value = Round(oParam.Value/10)*10 End If InventorVb.DocumentUpdate() oDim.Driven = True End Sub
Note that we're forced to work in cm instead of mm because we're directly accessing the value of the constraint instead of assinging it to a parameter, hence why I divided all of your values by 10.
Also, this will only work when there's only one driven constraint in the skecth. If this is a problem I can probably come up with something else.
Thank you very much! I would never have figured this out myself.
Where did you get you're knowledge of this? Is this just basic programming in VB or is this specific for iLogic in Inventor? Or a bit of both maybe. I'm a programming noob (know a bit of programming in C and even less in C#) but looking to learn more about it. Especially about VB if that is what I need to be able to program things like this myself.
Just one more question, is it also possible that whenever I have changed the value of the driven dimension by dragging it, that the rule is triggered and ran? The rule doesn't run when I trigger it by Any Model Parameter Change (one of the standard event triggers built in Inventor), where a driving parameter change by hand does.
Thanks very much again, you've helped me a great deal.
Robbert
iLogic is mostly VBA with some VB.net and special iLogic only functions mashed in. I taught myself using VB and VBA tutorials on the net, from this board, and lots of trial and error. One thing that's very very useful is the API's object browser. If you press F-11 from inside Inventor it will bring you to the API window. This is where you can write your own custom macros (This is pure VBA, not iLogic). If you press F2 from here it will bring you to the object browser. This doesn't translate perfectly to iLogic, but it can really help you understand what goes on under the hood of Inventor and can be a big help getting you ~90% of the way there.
Unfortunately, Inventor doesn't consider a reference dimension to be a regular parameter, so we can't use that as a trigger. However, If you go ahead and make your extrusion and set a trigger for "Part Geometery Change" then the rule is triggered whenever the sketch is dragged. I'm not sure if there's any other way to trigger it automatically. If the geometery change work around doesn't work for you then we could link it to the iTrigger function. If your not familiar with iTrigger, it's simply a ribbon button that creates a user parameter named "iTrigger0" and rolls its value up by one. I can't think of any other way to trigger the rule at the moment.
This conversation inspired me to create this idea for an iLogic object browser: http://forums.autodesk.com/t5/Inventor-IdeaStation/Object-Browser-for-iLogic/idi-p/3874083