I am about to embark on quite an ambitious project. I would like to write a VBA application (will later convert to plug-in, and ultimately and add-in) to generate the 3D models for a recurring project, but with different input parameters.
My customer builds a product (can't say more about that here), that consists of all manner of Inventor files (i.e. sheet metal parts, normal parts, weldments, sub-assemblies and ultimately a main assembly.
The product has about 12 different "standard" derivatives, but there are subtle changes from one project to the next within these derivatives.
Usually, once the product is modelled, the customer will make small changes that break away from his standard in order to save materials and various other reasons, so changes are inevitable, but they are usually fairly minor and can be controlled by using inventor parameters.
What I would like to do is the following. Using VBA generate a layout file that consists only of the skeletal model, but has all the parameters defining the product as user parameters. From there I want to flesh out and generate the 3D part, sheet metal etc. models by deriving this layout file into the individual parts and then inserting these parts back into the sub assembly files, weldment files and ultimately the final assembly file. I have done the project in this way manually in the past and it seems to be the best option.
At the moment I have a VBA macro written that is the start of the project. So far the macro creates some planes to use as sketch planes.
What I am struggling to figure out right now is; if I have created a plane using VBA macros using the "AddByPlaneAndOffset" method, (I have also created some user parameters), how do I determine the parameter name that is associated with the offset distance of that plane. Once I have this name, I want to edit the expression of that parameter (I think that's how it should be done) so that I can assign one of the user parameters to that model parameter. Ultimately, I would like to be able to "adjust" the position of any of the VBA created planes by changing the user parameters in the layout file.
It may be possible to solve this using iLogic, but somehow I have not had success with iLogic in the past for various reasons.
I have attached the VBA macro as it is at the moment for reference.
I know this is a long winded question / explanation, so thanks for taking the time to read through it.
Solved! Go to Solution.
This mod to your code should rename the LAST created paramter (i.e. the Plane Offset). It'll also allow you to the the user parameter as the expression. You'll probably want to pass both of these functions from elsewhere, but it does work.
Just make sure your parameter name does not have any illegal characters in it (spaces, brackets etc.)
Hope this is what you were looking for - I got a bit lost in your question!
Private Sub CreatePlane(refPlane As String, planeName As String, offset As Double, oDoc As PartDocument)
Dim oWorkPlane As WorkPlane
Set oWorkPlane = oDoc.ComponentDefinition.WorkPlanes.AddByPlaneAndO
oWorkPlane.Name = planeName
Dim oCompDef As PartComponentDefinition
Set oCompDef = oDoc.ComponentDefinition
Dim oParams As Parameters
Set oParams = oCompDef.Parameters
Dim oModelParams As ModelParameters
Set oModelParams = oParams.ModelParameters
Dim oModelParam As ModelParameter
Set oModelParam = oModelParams.Item(oModelParams.Count)
oModelParam.Expression = "=VARM002" '
oModelParam.Name = "GoatsCheese"
What you have suggested will work for me thanks.
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register
Start with some of our most frequented solutions to get help installing your software.