How do I retrieve a drawing dimension value with iLogic?

How do I retrieve a drawing dimension value with iLogic?

DALEROBERTSON1160
Observer Observer
2,212 Views
3 Replies
Message 1 of 4

How do I retrieve a drawing dimension value with iLogic?

DALEROBERTSON1160
Observer
Observer

I am writing a piece of code that will add text to a dimension. The added text will vary depending on the dimension value. The dimension is the distance between 2 end-holes of a series of equally spaced holes. For example: a series of 11 holes at 2.00 spacing will have a dimension of 20.00. I want to select the dimension, have iLogic to prompt for the hole-to-hole spacing, calculate the count and then add the text to the dimension ("10 EQ SP @ 2.00 = ").

 

The final dimension with the added text will look like this:

 

10 EQ SP @ 2.00 = 20.00

 

The critical step I am unable to solve is: getting the dimension value so I can perform the calculation.

 

I suppose it would be even better if I could window around the set of holes and dimension and have iLogic count them, calculate the spacing and add the text without prompting, but I'll settle for one step at a time.

 

(BTW, I know I stated there are 11 holes, that means there are 10 spaces. We state number of spaces so that the note reads like an equation (i.e. 10 x 2 = 20).)

 

Thanks,

 

Dale

0 Likes
Accepted solutions (1)
2,213 Views
3 Replies
Replies (3)
Message 2 of 4

Vladimir.Ananyev
Alumni
Alumni
Accepted solution

You should use GeneralDImension.ModelValue property to get the dimension value.

It returns the dimension value in database units as defined in the model or as measured in the drawing.

 

Sub GetDimValue()
 
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    Set oSheet = oDoc.ActiveSheet
    Dim oView As DrawingView
    Set oView = oSheet.DrawingViews.Item(1)
 
    Dim oGeneralDimensions As GeneralDimensions
    Set oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions
   
    'get the reference to some dimension
    Dim oDim As GeneralDimension
    Set oDim = oGeneralDimensions.Item(3)
 
    Debug.Print oDim.ModelValue  ' in base units (e.g., cm)
    Debug.Print oDim.ModelValueOverridden
    Debug.Print oDim.Text.Text
 
End Sub

 


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 4

DALEROBERTSON1160
Observer
Observer

Thanks Vladimir! I was very close with the code I have. The essential component was the ".Text" of:

 

 "oDim.Text.Text"

 

I studied the "Inventor 2014 API Object Model" but I couldn't quite nail down the syntax.

 

Thanks again!

 

Dale

0 Likes
Message 4 of 4

metamere
Contributor
Contributor

That's cool, thanks.  I can't seem to figure out how you find what item number a particular drawing dimension is (other than trial and error).  It seems like it is only accessible in the dimensions set, and nothing like that exists for a specific dimension.  Is there any way to directly check a dimension's item number so that you can refer to it specifically in code?

 

Thanks,

Ben

0 Likes