Thursday, March 2, 2017

iLogic: Driving the Model from the Drawing

I was teaching a class the other day when a student posed an interesting question.  He wanted to know if there was a way to drive an Inventor model from the drawing.  In the workflow he was trying to create, a sales person could generate proposal drawings by entering the needed parameters.  This way the user didn't even have to open the model.

I thought about ways to make that happen and iLogic seemed to be the easiest solution.    I was not 100% certain that I could get the drawing to update properly when the parameters were passed, so I wanted to test.  While testing, I found a way around that if the model does not cooperate.

The setup is simple.  You create a part or assembly that is driven by parameters, a typical iLogic workflow.  You then just need to create the same parameters in the drawing.  Then you can create a rule that passes the parameters between the drawing and the model.

Here is some sample code:

modelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)

Parameter(modelName & ".RailLength")= RailLength
Parameter(modelName & ".RailHeight") = RailHeight
Parameter(modelName & ".Color") = Color
Parameter(modelName & ".NoIntermediatePosts") = NumberOfPosts

iLogicVb.RunRule(modelName, "Update")

The first line finds the oldest view on the drawing and grabs the name of the model represented in that view.  This becomes important when using Copy Design, Replace Model Reference, or some other method that might change the model referenced in the view.  The file name is how the model is listed in the browser, which is how iLogic identifies the model.  The next four lines pass the drawing parameters to the model.

The last line is a way to get the model to update, if it does not automatically update.  It is a way of running a rule in the model that is there solely for the purpose of updating the model.

Here is a Screencast video where I show how this works on a sample model.



I will state that I was verifying this on several models.  I found that models that were using a component from the Frame Generator seemed to not update automatically, and didn't always respond to the extra rule that forced the update.  So any model that is using a Frame Generated component may need some extra effort to get updated.  I still have not found a foolproof way to accomplish the needed updates.