Trigger Drawing Rule to Run when View Placed on each Sheet?

Trigger Drawing Rule to Run when View Placed on each Sheet?

jake_egley
Advocate Advocate
267 Views
4 Replies
Message 1 of 5

Trigger Drawing Rule to Run when View Placed on each Sheet?

jake_egley
Advocate
Advocate

I have an ilogic rule that places the part no. and description in the corner of the current sheet using the first drawing view that was placed on the sheet. I would like to trigger this rule to run automatically when you place the first view on the sheet. Also, we make drawing packets where we use the same drawing and make a new sheet for each part. So I would like to trigger the rule to work on each sheet of the drawing.

 

I also have an ilogic rule that I run when I have placed a flat pattern on a sheet and it creates a note with laser area and perimeter info on the sheet. I would like this rule also to trigger when a flat pattern is placed on a sheet. Same as the other this would have to trigger on multiple sheets in the drawing.

 

And if both of these triggers can run at the same time since we use both rules on the same sheet. Am I asking for a miracle?

Jake Egley
Inventor 2022
0 Likes
268 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @jake_egley.  Good news and bad news... Good news is that what you are trying to do may actually be possible.  Bad news is that it will likely be time consuming and pretty complicated to figure out, and develop all the relatively advanced code that would be required to make all that happen the way you want.  The unfortunate fact is that there is no 'Event' specifically for when we add a drawing view to a drawing sheet.  So, what we would have to use instead is an 'Event' for when the Document 'changes'.  And yes, 'change' can be many different types of things, so a lot of checking & filtering would need to be done to narrow down what type of change has happened to the Document.  Not only that, but some changes are a collection of changes that happen at the same time, initiated by user interface commands, and behind the scenes commands that follow some of those commands.  So, sometimes we have to check the sequence of changes that have happened to the Document, to know when the exact right sequence happens to it that we are looking for.  Oh yea, and timing of the events also matters, because those events let us respond to them either 'before' or 'after' the action happens...or react during both phases.  You would have to become pretty familiar with how custom 'EventHandlers' work, instead of relying solely on the iLogic Event Triggers dialog.  And using custom event handlers is generally best done with Inventor add-ins, rather than iLogic rules, so there is that too.  😅

Don't give up though.  It may just take some time to learn, explore, test, and so on, taking this on as a project with multiple steps involved, rather than a quick task.

Below are a couple Links to the objects & events you would most likely be working with, from the Inventor API online help area.

ApplicationEvents 

ApplicationEvents.OnDocumentChange 

or

Document.DocumentEvents 

DocumentEvents 

DocumentEvents.OnChange 

I also attached a PDF of an old article I used to have posted online in my Contrubutions area, before they got taken down.  It really needs to be updated, and its example code is pretty poor, but it may help some, if you have never ventured into those areas before.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

WCrihfield
Mentor
Mentor

To give you a little bit of a head start, within the 'Context' that the OnChange event offers us, try to find a NameValueMap entry named "InternalName", then get its value, which should be a String.  It will contain the internal name of a ControlDefinition (AKA 'command') that was executed, resulting in the event happening.  The two command names to look for are:  "CreateDrawingBaseView" and "EditDrawingBaseView".  I believe there are 3 commands in the sequence to watch for...the create one, followed by two edit ones.  This is because immediately after we manually create a new base view in a drawing, it automatically launches a user interface dialog for us to edit that view that was just created, which is where we specify which model the view is referencing, which representations of the model, and other such settings.  So creating the view, then editing it the first time, are two different events, but those two actions must be completed before we can get a reference to the model that the view is referencing.

When that sequence of events has happened to a drawing type document, the event does not give you direct access to the new view object though, so you have to dig down into the document that the event happened within, then get its active sheet, because that is where a new manual view would have been placed, then check if that is the 'only' view on that sheet.  Because I usually also put a second base view on some of my drawings, for the ISO view.  If there is just the one view, then there is your reference to the view, and you can check things out from there.

I use a similar code based solution for copying all custom iProperties from the source model document to the drawing document, when I place the first view into a new drawing created from one of my drawing templates.  But all of our drawings are for one model document only, not multiple model documents (one drawing for each part, and one drawing for each assembly, only documenting that assembly, not its parts).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 5

jake_egley
Advocate
Advocate

Thank you @WCrihfield 

Jake Egley
Inventor 2022
0 Likes
Message 5 of 5

jwingateRJECD
Enthusiast
Enthusiast

As far as the first part of your problem, you should be able to set up your title block in the template to have a text box that is linked to the standard iproperties of the attached model.

 

jwingateRJECD_0-1749736881359.png

 

For the second part, something you could try is creating a custom boolean iproperty in the drawing template for 'Laser Area Marked' or something like that, and have a rule triggered by the 'before save' event that will first check to see if there is a flat pattern on the drawing sheet, and if so, then check to see if the boolean is true or false. If false, mark it up and change to true, if true, do nothing. Kind of a hokey way to get around it, but just an idea.