Inventor General

Reply
Active Contributor
Posts: 30
Registered: ‎04-08-2013
Message 1 of 12 (668 Views)
Accepted Solution

iLogic Driven Dimension

668 Views, 11 Replies
04-16-2013 05:37 AM

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

*Expert Elite*
Curtis_Waguespack
Posts: 2,566
Registered: ‎03-08-2006
Message 2 of 12 (633 Views)

Re: iLogic Driven Dimension

04-16-2013 07:20 AM in reply to: Blokkie862

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:

 

http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/iLogic-model-or-reference-parameter/m-...

 

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



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





Active Contributor
Posts: 30
Registered: ‎04-08-2013
Message 3 of 12 (613 Views)

Re: iLogic Driven Dimension

04-16-2013 11:54 PM in reply to: Curtis_Waguespack

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

*Expert Elite*
mrattray
Posts: 2,227
Registered: ‎09-13-2011
Message 4 of 12 (595 Views)

Re: iLogic Driven Dimension

04-17-2013 05:10 AM in reply to: Blokkie862
iLogic can't defy the universal rules of Inventor. You get an error like the one you saw when you tried. Rule of thumb is, if you can' do it via the UI, you probably (there are exceptions) can't do it through iLogic either.
By the way, I wouldn't try anymore of those Google solutions, that error is extremely generic and could apply to any of a million different issues.
Since you can't change the value of a driven dimension from the interface, you wont be able to change it via iLogic, either. If you change this driven dimension to driving via the UI does it throw an over constrained error? This would prevent iLogic from being able to do it as well.
Mike (not Matt) Rattray

Active Contributor
Posts: 30
Registered: ‎04-08-2013
Message 5 of 12 (592 Views)

Re: iLogic Driven Dimension

04-17-2013 05:28 AM in reply to: mrattray

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

*Expert Elite*
mrattray
Posts: 2,227
Registered: ‎09-13-2011
Message 6 of 12 (590 Views)

Re: iLogic Driven Dimension

04-17-2013 05:32 AM in reply to: Blokkie862

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!

Mike (not Matt) Rattray

Active Contributor
Posts: 30
Registered: ‎04-08-2013
Message 7 of 12 (586 Views)

Re: iLogic Driven Dimension

04-17-2013 05:41 AM in reply to: mrattray

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

*Expert Elite*
mrattray
Posts: 2,227
Registered: ‎09-13-2011
Message 8 of 12 (577 Views)

Re: iLogic Driven Dimension

04-17-2013 05:52 AM in reply to: Blokkie862

Can you post the file for me to look at?

Mike (not Matt) Rattray

Active Contributor
Posts: 30
Registered: ‎04-08-2013
Message 9 of 12 (576 Views)

Re: iLogic Driven Dimension

04-17-2013 06:00 AM in reply to: mrattray

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

 

 

*Expert Elite*
mrattray
Posts: 2,227
Registered: ‎09-13-2011
Message 10 of 12 (573 Views)

Re: iLogic Driven Dimension

04-17-2013 07:13 AM in reply to: Blokkie862

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.

 

Mike (not Matt) Rattray

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube