Part Revision update from drawing

Part Revision update from drawing

Kaplar.Balazs
Contributor Contributor
3,310 Views
10 Replies
Message 1 of 11

Part Revision update from drawing

Kaplar.Balazs
Contributor
Contributor

Hello there,

 

I searched through many forums but did not quite find the answer.

I'm using a custom template on my drawings with a customized title box. In the title box we add the Revision Number with a prompted entry so when we first create the drawing we set the rev number to A0. When a modification is needed the revision number has to change from either A0 -> A1 or B0, etc, so I have to manually edit the Field text of the title block. It feels clumsy and slow especially when dealing with multi sheet drawings for larger models.


I'm thinking of using the Part iProperties>Project>Revision Number value and changing the prompted entry to Properties - Model > Revision Number and make it a static value.

In this case I want to change the iProperties revision number without opening the part and manually editing the iProperties.

 

I'm not familiar with iLogic or Macros, so any suggestion is appreciated.

 

I attached a sample file and its drawing.

Thank you.

0 Likes
Accepted solutions (1)
3,311 Views
10 Replies
Replies (10)
Message 2 of 11

WCrihfield
Mentor
Mentor

Just so I'm understanding what you want correctly, are you wanting the that field in your drawings title block to only show the value of the Revision Number iProperty from the model document?  I noticed that right now it is showing the value of the Drawing's Project iProperty, followed by the value of the prompted entry labeled Modositaskod.  So right now it doesn't appear that you are using the Revision Number iProperty from either document for anything, right?

I'm not 100% sure what you are trying to accomplish, but from the sounds of it, I'm thinking you may not even need to use any iLogic or macros.

By the way, I'm having a hard time translating the words in your document, so I'm curious what language that is, if you don't mind (I'm guessing Hungarian, but not sure.)?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 11

Kaplar.Balazs
Contributor
Contributor

Hi, thanks for your quick answer.

 

Yes, it is indeed in Hungarian. 

We are using a macro to fill the drawing number bracket, this includes the VT- prefix, drawing number (1395-013-001) then the prompted entry - Módosításkód - which is the Revision Number in hungarian.

 

What I'm trying to do by changing the Prompted entry to the iProperty Revision Number is to avoid manually editing the title block field text when the model changes. For this I'm looking for a way to edit the model iProperty from either the drawing or part environment, and I don't want to open the iProperties every time I need to change something.

 

Also my template includes some Sketch Symbols which also uses the Revision Number iProperty and this would be helpful to edit the number with just a mouseclick or hotkey.

 

I hope this explains it clearly.

 

Thanks in advance.

0 Likes
Message 4 of 11

WCrihfield
Mentor
Mentor

First step - editing your drawing template title block definition's sketch, double click on that "Modositaskod" text to edit it, then change the drop-down menu from 'Prompted Entry' to 'Properties - Model', then the next drop-down from the initial 'APPEARANCE' property to the 'REVISION NUMBER' property.  It seems like that will fix the drawing title block issue, so you don't have to manually edit/fill-in a prompted entry anymore.

Title Block Revision Formatted Text Property Change.png

 

But now, you still want to be able to easily edit the model's Revision Number value from the drawing, without having to open the iProperties dialog, right?  You will have to have some sort of dialog to be able to enter/edit text in, so the next best options are either an InputBox (shown directly by either an iLogic rule or VBA macro), or a Form (iLogic or VBA UserForm - also launched by either an iLogic rule or VBA macro), that just has the one property listed and a textbox where you can change its value.  Obviously the InputBox would be easier to implement, if you choose to go that route.  If we go the iLogic route, then do you want it to be a 'local' rule, or an external rule?  And if we go the VBA route, do you want the macro to be in the DocumentProject, or the ApplicationProject?

 

In the case of a local rule solution, here is an example rule code for editing the model revision number's value.

 

Dim oDDoc As DrawingDocument = ThisDrawing.Document
If ThisDrawing.ModelDocument Is Nothing Then
	MsgBox("There is no 'model' referenced in this drawing yet. Exiting.", , "")
	Exit Sub
End If
Dim oMDoc As Document = ThisDrawing.ModelDocument
'if this doesn't work due to language difference, you can
'specify the property set by its Index Number (1) and the property by its PropID (9) or its Index number (7).
'Dim oRevNumProp As Inventor.Property = oMDoc.PropertySets(1).ItemByPropId(9)
Dim oRevNumProp As Inventor.Property = oMDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number")
Dim oRev As String = InputBox("Enter/Edit Model Revision Number.", "MODEL REVISION", oRevNumProp.Value)
oRevNumProp.Value = oRev
oMDoc.Save2(False)

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 11

Kaplar.Balazs
Contributor
Contributor

Thanks for the detailed reply.

 

The first step was clear to me, just the second part gave me some headache.

I never worked with rules or vba, I'm using the macro which a college of mine made many years ago and he's not working with us anymore, sadly no one is familiar with VBA or iLogic rules right now.

 

I need to create an iLogic rule then paste the code into it right?

Do I need to add this rule to every template or can I make a "global" rule and use it for all my templates?

 

Can you give me a headstart for this? I would really appreciate it.

0 Likes
Message 6 of 11

WCrihfield
Mentor
Mentor

Yes to use the code I supplied earlier, you would create a new iLogic rule, then copy/paste that code into it, then click the 'SAVE' button on the rule editor dialog.  Then, when you are not within the rule editor, and you want to run that rule manually, just go to the iLogic tab/browser in that document, then make sure the top sub-heading 'Rules' is active, then right-click on that rule below and choose 'Run'.  The code I supplied was designed to be used as a 'local' rule (saved within the document it is to work on).  But if you have a lot of drawing template files that you would like to use something like this in, it may be a good idea to make an external iLogic rule for them all to use.  That way if you ever need to update it or change something, it can be done in one place, one time.  Let me know if you would rather go that route.  We could also create another VBA macro, if you are more comfortable with that option, but the code I supplied wouldn't work in a VBA macro, because the coding layout/style is different.  I can write in in VBA though, if needed.

 

(iLogic uses VB.NET coding, while VBA uses VBA coding - both descended from Visual Basic, so they are similar, but just different enough to cause a lot of headaches.)

 

Then there is the question of how and when you want to run this rule.  As it is right now, this rule would need to be ran manually whenever you wanted to use it, because there is nothing within it that will cause it to automatically run for any reason or event.  There are many options for setting up the 'how and/or when' a rule is run.  There are some built-in 'Event Triggers' that would cause the rule to run automatically when those events happen, but I don't think any of them will be a good fit for this situation.  If we used a VBA macro, then you will have the ability to put a button for that macro somewhere in your ribbon, for a single click run, but you would still have to click it to run it, instead of it being automatic.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 11

Kaplar.Balazs
Contributor
Contributor

Thanks for explaining. I tried your code and it works. Although I have to click on iTrigger then save the document otherwise the RevNumber doesn't show up.

 

Everytime the model changes (either a dimension, material, heat/surface treatment added, etc) the revision number goes up 1 digit. I change sg on the model, then update the drawing then set the new rev number. This happens frequently during machine assembly and production.

We are already using a macro button to fill the title block so I'd go that way for this operation. My goal with this whole thing is to save myself (and for my colleges) unnecessary mouseclicks and provide a mistake-proof update when altering the product models.
We aren't really using Inventors capabilities to the maximum (tbh, we are very basic) so this small addition would be a great leap towards a more productive work environment.

0 Likes
Message 8 of 11

WCrihfield
Mentor
Mentor
Accepted solution

I think having to click the iTrigger then save the document, is just updating the document, so the changes show up.  I think we can add one or two more lines to the end of the code to make that happen.  At the end of that rule code add these two lines:

 

oDDoc.Update2(True)
oDDoc.Save2(False)

 

Here are the links to the online help pages that document the 'Update2' method, and the 'Save2' method.

Give that a try first, just to see if that does the trick, so you don't have to click iTrigger & save.

 

Now for the VBA macro code.  Here you go:

 

Sub EditModelRevFromDrawing()
    'check 'active' document's type, to avoid potential errors
    If ThisApplication.ActiveDocumentType <> kDrawingDocumentObject Then
        Call MsgBox("This macro only works while a Drawing is active. Exiting macro.", , "")
        Exit Sub
    End If
    Dim oDDoc As DrawingDocument
    Set oDDoc = ThisApplication.ActiveDocument
    
    'attempt to get the 'model' document
    'can't use ThisDrawing.ModelDocument in VBA, like you can in iLogic
    'find first drawing view which is representing a 'model' document
    Dim oSheet As Inventor.Sheet
    Dim oView As DrawingView
    Dim oMDoc As Inventor.Document
    For Each oSheet In oDDoc.Sheets
        For Each oView In oSheet.DrawingViews
            If oView.ReferencedDocumentDescriptor.ReferencedDocumentType = kAssemblyDocumentObject Or _
            oView.ReferencedDocumentDescriptor.ReferencedDocumentType = kPartDocumentObject Then
                Set oMDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
                Exit For
            End If
        Next
    Next
    If oMDoc Is Nothing Then
        Call MsgBox("There is no 'model' referenced in this drawing yet. Exiting.", , "")
        Exit Sub
    End If
    
    Dim oRevNumProp As Inventor.Property
    Set oRevNumProp = oMDoc.PropertySets(1).ItemByPropId(9)
    Dim oRev As String
    oRev = InputBox("Enter/Edit Model Revision Number.", "MODEL REVISION", oRevNumProp.Value)
    oRevNumProp.Value = oRev
    oMDoc.Save2 (False)
    oDDoc.Update2 (True)
    oDDoc.Save2 (False)
End Sub

 

Do you know what to do from here, to use it?

If not, I'll try to explain:

  • Open your VBA Editor dialog
  • Make sure the Project Explorer window is open:  Ctrl+R on keyboard, or View menu > Project Explorer
  • Under your ApplicationProject (in the Project explorer window), select, then right click on the folder called "Modules", and click on the 'Insert...' slide-out, then choose 'Module'.
  • Make sure your Properties window is open:  Either the F4 keyboard key, or View menu > Properties Window
    • While you have your new Module selected (in the Project explorer window), you will see the module's name at the top of the Properties window.  Select the name text, and change it to "EditModelRevFromDrawing" (This will ensure our module will be using the same name as our macro, to make it easier if/when you decide to create custom button icons for it later.)
  • Now back in the Project explorer window, right click on the new macro, and choose 'View Code'.  This will open a window where you will need to paste this code into.  Then paste this code into it.  Then click the Save button on your tool bar (or File menu > Save (project) ; or Ctrl+S on your keyboard)
  • Now your new macro is created and ready to be used, but you still need to put a button into your ribbon somewhere, so you can run it with a single click.  Go ahead and close the VBA Editor now, because we shouldn't need it anymore.
    • The easiest way to add a button for a macro into your ribbon is open the tab of your ribbon where you want to put it, then right click somewhere on that ribbon and choose "Customize User Commands...".  This will open a dialog labeled 'Customize'.  Make sure your on the 'Ribbon' tab (top left corner).
    • In the 'Choose commands from' drop-down list (upper left, below tabs), choose 'Macros'.
    • Now find your new macro in the list on the left, select it, click the >> button in the middle to move it over to the right window.  Now check whichever checkbox options you want, then click the OK (bottom right).

That should be about it.  Let me know if you run into any trouble with any of that.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 11

Kaplar.Balazs
Contributor
Contributor

Hello again,

 

Sorry for my late reply. I just want you to know I haven't gone missing, just busy catching up with my delayed projects and doesn't have much free time to explore Inventor right now.

I really appreciate your help and code, as soon as I have the time to try it I'll let you know.

 

Thanks again,

 

Balázs

0 Likes
Message 10 of 11

Kaplar.Balazs
Contributor
Contributor
Hi WCrihfield,

Thanks again for your knowledge and help. The macro works as I intended to use it.
If I have questions in the future about macros I'll ask if you allow 🙂

Cheers,
Balázs
0 Likes
Message 11 of 11

WCrihfield
Mentor
Mentor

Sure.  Feel free to ask any questions you want, whenever you want.  That's a big part of what these forums are all about.  You can also try typing your questions into the search engine at the front page of this forum, to see if others have asked the same questions, and may already have answers posted.  I'm glad to be able to help out where I can.  Good luck. 🙂

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes