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?!? |
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! |
Hi,
ReplyDeletevery 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?
NFAA, thanks for the comments.
ReplyDeleteI'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!
I have written a macro under IV 2011 to do that, even with multiple sheets drawings.
ReplyDeleteThe 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...
Guillaume,
ReplyDeleteThat is awesome. I'm going to have to give that a try.
Thanks for sharing that tip!
Happy it can help you :)
ReplyDeleteGreat help mate.
ReplyDeleteI have been looking for this code for months.
Thanks
I'm glad you found the info helpful!
ReplyDelete"Super Genius" comes to mind -
ReplyDeleteGuillaume, what do you mean by VB function?
ReplyDeleteGuillaume, when I say VB function, I'm referring to Visual Basic. You can write macros for Inventor using that.
ReplyDeletewith this you'll get 1:4 for example
ReplyDeleteDim strScale As String = ActiveSheet.View("VIEW1").ScaleString
iProperties.Value("Summary", "Keywords") = strScale
Use in the template of your drawing
Thanks! I appreciate the tip!
ReplyDeleteHello Jonathan,
ReplyDeleteI realize it's been some time since you posted this but have you revised, improved or re-visited this effort ?
Kind regards,
Karl
Karl,
ReplyDeleteI 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.
Hello,
ReplyDeleteI 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:
"1:"
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
Luis
Luis,
ReplyDeleteI 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.
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.
ReplyDeleteIt looks like the hook isn't open to update the drawing.
I hope this helps!
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.
ReplyDelete-----------------------------------
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
Try
Dim CurrentScale As String = ThisDoc.Document.Sheets(1).DrawingViews(1).ScaleString
Catch
MessageBox.Show("Create View First","No Views Available",MessageBoxButtons.OK,MessageBoxIcon.Error)
Return
End Try
Try ' Check for other View Scale Source via Custom iProperty
OtherScale = iProperties.Value("Custom", "CustomViewScale")
Catch
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
Else
DisplayScale = ViewScale & " : 1"
End If
iProperties.Value("Custom", "Drawing Scale") = DisplayScale
InventorVb.DocumentUpdate()
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")
Try
prop = customPropertySet.Item("CustomViewScale")
Test = 0
Catch
' 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")
'customPropertySet.Delete("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
Try
Qty = ThisDoc.Document.Sheets(1).DrawingViews.Count()
Extra = ThisDoc.Document.Sheets(1).DrawingViews(1).Name
Catch
MessageBox.Show("Create View First","No Views Available",MessageBoxButtons.OK,MessageBoxIcon.Error)
Return
End Try
Dim MyViewList As New ArrayList
For Each viewname In ThisDoc.Document.Sheets(1).DrawingViews
'MsgBox(viewname.Name)
MyViewList.add(viewname.Name)
Next
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")
Try
prop = customPropertySet.Item("CustomViewScale")
Catch
' Assume error means not found
customPropertySet.Add("", "CustomViewScale")
End Try
iProperties.Value("Custom", "CustomViewScale") = MyView
End If
iLogicVb.RunRule("Check_Scale")
iLogicVb.UpdateWhenDone = True
Kris,
DeleteThanks for the sample code! I'll have to take a look a it! :-)
AND IF I WANT IN 3/4"=1'-0"
Delete???
I tried this and the first part (Check Scale) runs perfectly. Thanks!
DeleteBut 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?
EACH SHEET HAVE A SAME SCALE???? ITY'S POSSIBLE TO SET THE FIRST VIEW IN EACH SHEET AND IN ARCHITECTURAL UNIT?
ReplyDeleteI 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.
ReplyDelete