Find us on Google+ Yielding to Logic - Extracting Drawing Scale with iLogic ~ Inventor Tales

Sunday, August 15, 2010

Yielding to Logic - Extracting Drawing Scale with iLogic

“The logic of words should yield to the logic of realities.”
Louis D. Brandeis

Just this Friday, I was posed what I thought was an easy, five minute, question.  "How do I place the view scale into the title block?"

My inside voice said, Pffft!  No problem!  After all, there's a spot right there for it in the title block already!

Scale is already there! 

So I go into my title block definition, and look for the iProperty that accesses the drawing scale. It should be a slam dunk.  All I have to do is choose the property that calls the scale.  But as I look, my stomach sinks.

Here they are.  All I have to do is choose one.  But wait?!?
It isn't there.  Scale isn't available.  I think I know why this is.  In many cases, the scale can easily vary from view to view, so which do you call? 

I puzzle over this a bit.  I bounce it off of Javier Chavez, one of my KETIV team members.  He confirms what my eyes see.  The scale isn't there.

So, now, as they say, it's time to execute 'Plan B'.  Which means, I have to develop a 'Plan B' to execute. 

Now I'm pacing about my little office, rubbing my chin, and annoying my coworkers with my heavy footfalls. 

After a few moments, I have 'Plan B'.... iLogic!

iLogic to the rescue!

So I create a new iLogic rule, and enter the following code below (with comments):

'Forces update after rule runs
iLogicVb.UpdateWhenDone = True
'Extracts scale from 'View 1' on drawing sheet' to a field named SCALE
SCALE = ActiveSheet.View("VIEW1").Scale
 'Writes scale to a custom iProperty named SCALE
iProperties.Value("Custom", "SCALE") = SCALE

Here's the rule in context of the iLogic editor.

In short, the code extracts the scale of the first drawing view via the API, and writes it to a custom property.  With the scale written to a custom property, NOW I have something I can extract for the Title block!

SCALE custom iProperty

With this field added to the title block, I'm in business.

The custom iProperty

With that being done, is the rule perfect?  Frankly, no.  I have work left to do.

This is what's still on my to do list.

1) My triggers don't update completely every time.  Just like Rule #2 of Zombieland, I have to 'Double Tap' the update button once in a while.  I want to go over it and make sure it updates consistently.

Still have to work on the triggers some more

2) The view has to be called 'VIEW1'.  If it's not, or if you delete the first view and place another (now called VIEW2) the rule will bark about not having 'VIEW1'.  So there's a little work to be done to remedy that.

But I think the backbone of the routine is solid, and I'm willing to take a little time to revel in a small victory, if only for a few seconds.  I don't consider myself one of the iLogic 'gunslingers' so sometimes you have to 'Enjoy the Little Things'.

Which by the way, is Rule #32 of Zombieland!  :-)

As I learn more, and improve the rule, I'll post updates!

Happy Inventing!

P.S.  It's back.  Autodesk Manufacturing Academy is back, hosted by KETIV in Cerritos and Oregon.  Come see us in October!   And check out the videos from last years session HERE!

***UPDATE 20-March-2012 ***

After some hunting around, and help from a friend or two, it looks like teh direct update can't be triggered right when the view scale changes.  But if an event trigger is set to run "Before Save Document".  The rule scale will update when you save.  I tried it in Inventor 2012, and it works!

Here's the ticket!


  1. Hi,
    very simple and nice ilocig code. Do you know if it's possible to keep the scale 1:4, and not convert it to 0,25 when it's written to custom properties?

  2. NFAA, thanks for the comments.

    I'm afraid I don't off the top of my head to convert to a '1:4' format.

    Possibly through full blown VB.Net, but that's all I can't think of at the moment.

    I'll keep my eyes open to see if I locate anything though!

  3. Guillaume6:16 AM

    I have written a macro under IV 2011 to do that, even with multiple sheets drawings.
    The value to take is not SCALE but "ScaleString" from which you will get the "1 : 4" or else...

    You can even format it to become "1/4" if needed (use the VB function replace as follow
    replace (mystring," : ","/")
    that's it...

  4. Guillaume,

    That is awesome. I'm going to have to give that a try.

    Thanks for sharing that tip!

  5. Guillaume2:27 AM

    Happy it can help you :)

  6. Anonymous9:33 AM

    Great help mate.
    I have been looking for this code for months.


  7. I'm glad you found the info helpful!

  8. "Super Genius" comes to mind -

  9. Anonymous1:39 PM

    Guillaume, what do you mean by VB function?

  10. Guillaume, when I say VB function, I'm referring to Visual Basic. You can write macros for Inventor using that.

  11. Anonymous12:24 AM

    with this you'll get 1:4 for example

    Dim strScale As String = ActiveSheet.View("VIEW1").ScaleString
    iProperties.Value("Summary", "Keywords") = strScale

    Use in the template of your drawing

  12. Thanks! I appreciate the tip!

  13. Anonymous2:35 PM

    Hello Jonathan,
    I realize it's been some time since you posted this but have you revised, improved or re-visited this effort ?

    Kind regards,


  14. Karl,

    I haven't looked at this one in some time. I'll have to revisit it now that we're back in 2012.

    It's proving to be a hectic few weeks, but I'll try to pull it up and at least give it a quick check.

  15. Anonymous8:42 AM


    I really love this tip, but it seems that I find a problem using on a Vault Enviroment, I was unable to save or check-in a previus checkedin file until I supress the automatic scale rule, I also modified the rule in order to convert decimal values without using VB:

    SCALE = ActiveSheet.View("VISTA1").Scale
    iProperties.Value("Custom", "SCALE") = 1/SCALE

    my title block text has:

    This works really well because we use always reduction scales, but only the first time, once we need to modify the file, we face the vault problem, so we supress the rule & run it manually before print or save.

    We really need an update on this one.

    Thanks for your efforts on this blog, the tips and stories you share

    Kind Regards


  16. Luis,

    I never have found a way to crack that double tap thing. I've tried all the updates I can think of at least.

    But I did bounce it off one of my teammates to see if a fresh set of eyes might help.

    I can't make any promises, but if we find something, I'll update everyone.

  17. After a bit of digging around, it looks like the only way to automate it is to create an event trigger, to "refire" the rule before a save.

    It looks like the hook isn't open to update the drawing.

    I hope this helps!

  18. One of these days I will have to break into the VB Macro side of things, but keeping it inside of iLogic here is a solution for the 'wrong view' errors.

    First is the simple bit of getting/checking and setting the scale based on the existance of a view and the optional existance of a custom iProperty labeling an alternate view for scale - needs an error check to supply if the iproperty view exists, second rule assigns alternate view.
    '==== Check Scale =================================
    'iLogic Sequence to Set First View Scale to Custom iProperty for Titleblock Useage - Also Adds check for alternate view source for scale

    Dim CurrentScale As String = ThisDoc.Document.Sheets(1).DrawingViews(1).ScaleString
    MessageBox.Show("Create View First","No Views Available",MessageBoxButtons.OK,MessageBoxIcon.Error)
    End Try

    Try ' Check for other View Scale Source via Custom iProperty
    OtherScale = iProperties.Value("Custom", "CustomViewScale")
    OtherScale = ThisDoc.Document.Sheets(1).DrawingViews(1).Name
    End Try

    ViewScale = ActiveSheet.View(OtherScale).Scale

    If ViewScale < 1 'Create appropriate String for Display of Scale ------- Future will include check of non-standard scales
    DisplayScale = "1 : " & 1 / ViewScale
    DisplayScale = ViewScale & " : 1"
    End If

    iProperties.Value("Custom", "Drawing Scale") = DisplayScale


    If OtherScale = ThisDoc.Document.Sheets(1).DrawingViews(1).Name 'Check to see if Custom iProperty for Alternate view is present, suggest deletion if true
    customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
    prop = customPropertySet.Item("CustomViewScale")
    Test = 0
    ' Assume error means not found
    Test = 1
    End Try

    If Test = 0 Then MessageBox.Show("Delete Custom iProperty Named: CustomViewScale","Unnecessary iProperty",MessageBoxButtons.OK,MessageBoxIcon.Error)
    'iProperties.Delete("Custom", "CustomViewScale")
    End If

    Next iLogic Code
    '===Change View for Scale===================================
    'Has to be Manually Run
    'Change View Source for TB Scale - Add custom iProperty with alternate view name in case of requirement of non-base view scale

    Qty = ThisDoc.Document.Sheets(1).DrawingViews.Count()
    Extra = ThisDoc.Document.Sheets(1).DrawingViews(1).Name
    MessageBox.Show("Create View First","No Views Available",MessageBoxButtons.OK,MessageBoxIcon.Error)
    End Try

    Dim MyViewList As New ArrayList

    For Each viewname In ThisDoc.Document.Sheets(1).DrawingViews

    MyView = ThisDoc.Document.Sheets(1).DrawingViews(1).Name

    MyView = InputListBox("Select View to Read Scale from for the Drawing TitleBlock.", MyViewList, MyView, Title := "Title", ListName := "List")

    If MyView <> ThisDoc.Document.Sheets(1).DrawingViews(1).Name
    customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
    prop = customPropertySet.Item("CustomViewScale")
    ' Assume error means not found
    customPropertySet.Add("", "CustomViewScale")
    End Try

    iProperties.Value("Custom", "CustomViewScale") = MyView
    End If


    iLogicVb.UpdateWhenDone = True

    1. Kris,

      Thanks for the sample code! I'll have to take a look a it! :-)

    2. Anonymous4:04 AM

      AND IF I WANT IN 3/4"=1'-0"

    3. I tried this and the first part (Check Scale) runs perfectly. Thanks!

      But when I run the second part (Change View for Scale) I get the following error message: "RunRule: Cannot find a rule with the name: 'Check_Scale'."

      Should both parts be in the same rule or in two separate ones?

  19. Anonymous4:07 AM


  20. I actually just made this a prompted entry and if I'm wrong I just have to edit text in the title block field. This way if I have multiple sheets that are different sizes and scales it's an easy input.