Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

new to writing macros

17 REPLIES 17
Reply
Message 1 of 18
cadman777
761 Views, 17 Replies

new to writing macros

Guys ...
I'm new to Inventor macros (using IV2010).
I don't know VB.
I did a little LISP in past years, but it's difficult b/c I'm not a 'man of word' so to speak.
But, I need to automate some tasks on multiple files (200+ ipt's and a few iam's).
The best solution, if I was in Autocad, would be LISP.
Am I correct in assuming the best solution in Inventor is Macros?
If so, is there any hope for me learning it in a few hours and writing a simple macro that will operate on multiple files that are on disk?
If not, then is there any hope for me learning it in a few hours and writing a simple macro that I can use on a file-by-file basis after opening each file?

Here's what I want to accomplish:
I have to assign Iproperty names to dimension tags so that a BOM in an idw will populate.
I have someone else's assembly, which was not created the way I do, so that it won't register in the BOM each part's size dimensions.
My customary iprop BOM tags are the same as Inventor's defaults:
G_L=length
G_W=width
G_T=thickness
G_D=diameter
I just need to get them into each part.
Unfortunately, each part file has different dim tags assigned to the target dimensions.
For example: d1 may be G_L in one part, but it may be G_D in another part, but it may not even matter in another part (like a sheet metal part).

This is what I've been doing, which is giving me wrist and hand pain on account of the persistent repetitive use of the same keys and mouse motions:
1. standard part: dimension display=expression (default was tolerance in every part);
2. standard part: right click the base feature to 'show dimensions' (so I can see which dim tags i need to change in the parameter's dialogue);
3. standard part: open 'parameters' dialogue, and assign BOM tags to the correct dim tags (i.e., G_L ... etc per above).
4. standard part: some parts need a 'user parameter' in the 'parameters' dialogue box b/c the G_L or G_W is a composite/equation of 2 or more dimensions (like lift eye is a box with full radius arched top)
5. sheetmetal part: same as above, except for length or width (depending on where the bend occurs) open the 'iproperties>custom> tab and create the appropriage BOM tag such as:
G_L
Text
=cm
6. I also want a macro that adds all of the above custom iproperty colums to an iam BOM, so I can check to make sure I didn't miss any dim tags.

The BOM is already setup in a GA idw file, so all that needs be done is fix every part.
That's a LOT of repetitive work to do to 200+ files.
It's even more work to do 'in a rush' ... b/c it is needed 'yesterday'.
Thanks for your suggestions ... Chris Edited by: cadman777 on Apr 16, 2010 8:37 AM
... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
17 REPLIES 17
Message 2 of 18
Anonymous
in reply to: cadman777

I am not sure I follow what you are wanting to change on the G_L values, but
you can access them as easily as this

Public Sub FindG_L()

Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oParams As Parameters
Set oParams = oDoc.ComponentDefinition.Parameters

Dim oParam As Parameter
Set oParam = oParams("G_L")

MsgBox oParam.Name & " : " & oParam.Value


End Sub

--
KWiKMcad
Kent Keller
"cadman777" wrote in message news:6374248@discussion.autodesk.com...
Guys ...
I'm new to Inventor macros (using IV2010).
I don't know VB.
I did a little LISP in past years, but it's difficult b/c I'm not a 'man of
word' so to speak.
But, I need to automate some tasks on multiple files (200+ ipt's and a few
iam's).
The best solution, if I was in Autocad, would be LISP.
Am I correct in assuming the best solution in Inventor is Macros?
If so, is there any hope for me learning it in a few hours and writing a
simple macro that will operate on multiple files that are on disk?
If not, then is there any hope for me learning it in a few hours and writing
a simple macro that I can use on a file-by-file basis after opening each
file?

Here's what I want to accomplish:
I have to assign Iproperty names to dimension tags so that a BOM in an idw
will populate.
I have someone else's assembly, which was not created the way I do, so that
it won't register in the BOM each part's size dimensions.
My customary iprop BOM tags are the same as Inventor's defaults:
G_L=length
G_W=width
G_T=thickness
G_D=diameter
I just need to get them into each part.
Unfortunately, each part file has different dim tags assigned to the target
dimensions.
For example: d1 may be G_L in one part, but it may be G_D in another part,
but it may not even matter in another part (like a sheet metal part).

This is what I've been doing, which is giving me wrist and hand pain on
account of the persistent repetitive use of the same keys and mouse motions:
1. standard part: dimension display=expression (default was tolerance in
every part);
2. standard part: right click the base feature to 'show dimensions' (so I
can see which dim tags i need to change in the parameter's dialogue);
3. standard part: open 'parameters' dialogue, and assign BOM tags to the
correct dim tags (i.e., G_L ... etc per above).
4. standard part: some parts need a 'user parameter' in the 'parameters'
dialogue box b/c the G_L or G_W is a composite/equation of 2 or more
dimensions (like lift eye is a box with full radius arched top)
5. sheetmetal part: same as above, except for length or width (depending on
where the bend occurs) open the 'iproperties>custom> tab and create the
appropriage BOM tag such as:
G_L
Text
=cm
6. I also want a macro that adds all of the above custom iproperty colums to
an iam BOM, so I can check to make sure I didn't miss any dim tags.

The BOM is already setup in a GA idw file, so all that needs be done is fix
every part.
That's a LOT of repetitive work to do to 200+ files.
It's even more work to do 'in a rush' ... b/c it is needed 'yesterday'.
Thanks for your suggestions ... Chris

Edited by: cadman777 on Apr 16, 2010 8:37 AM
Message 3 of 18
Anonymous
in reply to: cadman777

I forgot to mention that if you are using a 32 bit machine I have a addin on
my site www.kwikmcad.com that will batch run macros on files. I am working
on updating it to 64 bit, but it won't be ready this week.

--
KWiKMcad
Kent Keller
Message 4 of 18
cadman777
in reply to: cadman777

Kent,
Thanks for the info.
I'll check out your tool.
Actually, I'm interested in doing the reverse of what you show.
Instead of accessing the 'G_L' parameter name, I want to assign it to an existing dimension's parameter name.
Then I need to 'export' that parameter name so it can be used in an idw bom.
the problem is, I 'inherited' a project that was created where none of the ipt files have any exported basic feature dims. So it's impossible to generate a 'cut list' in an idw from these parts.
I've been changnig them all manually, one-at-a-time, and it's eatnig the clock while straining my hands and neck.
I wish there was an easy way to automate these and other tasks.
Maybe I need to learn VB??
Cheers ... Chris
... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 5 of 18
Anonymous
in reply to: cadman777

To change the name isn't too much different from the code Kent posted. It
would be something like this to change the parameter named "d1" to "G_L".

Public Sub ChangeToG_L()
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oParams As Parameters
Set oParams = oDoc.ComponentDefinition.Parameters

Dim oParam As Parameter
Set oParam = oParams.Item("d1")

oParam.Name = "G_L"
End Sub

I think the tricky thing in your case is likely figuring out what the
existing parameter is that you want to rename to G_L. You said you're
currently turning on the display of the dimensions and looking to see which
dimension defines what. Finding these obvious kind of things is very easy
for a human but very difficult to describe the process for in a program.
--
Brian Ekins
Inventor API Product Designer
http://blogs.autodesk.com/modthemachine
Message 6 of 18
cadman777
in reply to: cadman777

Brian,
Thanks for the additional code.
Maybe with a little help, I can learn enough of this 'language' to get-by?
Your comment seems reasonable:
>Finding these obvious kind of things is very easy for a human but very difficult to describe the process for in a program.
A program for this kind of activity would require a 'pause for user input' and a 'repeat loop' (like in some of my Autodad LISP files, which required a lot of forethought, reworking and 'hair-pulling' to cover all the possible contingencies).
Cheers ... Chris
... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 7 of 18
Mike.Wohletz
in reply to: cadman777

I think that it would be faster to have the program display the sketch and then use the select event with a dialog prompting for each of the required items that you are trying to retrieve. once you select it you would just call the code to change the current sellected item and it is done.

also are any of these items sheetmetal parts? if so you can get the length and width from the flat pattern with a very simple add-in.

Mike
Message 8 of 18
cadman777
in reply to: cadman777

Mike,
Excellent idea.
Your procedure would be a viable way to solicit user input by prompting the user to pick the dimension that applies to 'length', then 'width', then 'thickness', then 'height', then 'diameter', etc.
I wrote a very nice (and simple) lisp routine that is used to transfer text values from one text entities into another by clicking on one then the other (similar to 'match props'). It's the same exact thing, only a different prgramming language.
The only caveat in sheet metal flat patterns is the need to make sure the f.p. model is properly oriented for 'width' and 'length', so the width is the narrowest side while the length is the longest side.
Another caveat is the need to sometimes stack dimensions into a formula to create one of the custom properties needed for the bom.
The biggest caveat is that I don't know how to program in VB and my lisp skills are nowhere to be found.
Cheers ... Chris
... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 9 of 18
Mike.Wohletz
in reply to: cadman777

Chris
I don't know that you are needing the actual parameters reset to a new name or that you are looking to always have the G_L,G_T, etc. exposed in the custom properties to be used in drawings etc. if this is the case then I would create custom parameters that are exposed and only have your add-in set them to the value of the selected item. My reasoning behind this is if you pick something to be G_L and then realize that you need to make a change or that the wrong thing was picket you are going to need to rename the current G_L to something else before giving another parameter that G_L name, if all you are ever doing is setting G_L to = d1 then it is not a problem and no more work is needed to simply change it to = d5.

I don't know if you have looked at Brian's blog http://modthemachine.typepad.com/ but he is the king of code in my opinion for Inventor, I will show you how it is done but I am short of time for the next couple of days. perhaps Brian can give us an example of how to do this. 🙂
Message 10 of 18
cadman777
in reply to: cadman777

Mike,
I'm not sure I understand exactly what the work-flow is for this.
What's happening is I want to use it on a load of part files I inherited from some unknown person who didn't assign any exportable bom iprop names to the dims in the parts (except the ones from the C/C, which would need to be selected for 'export').
Also, if it works real good, I can use it on my own part files. I could get lazy and not assign any bom iprop names to any of the dims while creating the parts. then at the end, the bom iprop names can be assigned all at once. it would save a lot of tedium during the modeling process, esp w/frame generator and other c/c and sheetmetal parts.
Brian's pages have a LOT of good info on them. Thanks for pointing them out.
... Chris
... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 11 of 18
Mike.Wohletz
in reply to: cadman777

That is what I thought you wanted to do with them, if you go to the parameters and create a new parameter named G_L and lets say that d2 is the parameter that you are wanting to use for the length then the value of the new G_L parameter that you have just created is now d2. the reason for this is that if you are going to change the name of the parameter to a set name you are going to need to handle renaming it to something else if the first time you got it wrong. ie you cant have two parameters named G_L.
Message 12 of 18
cadman777
in reply to: cadman777

Mike,
Yes.
I read Brian's articles on iproperties.
They are very good (simple, concise, linear).
They remind me of the ways I used LISP in autocad.
I believe I'd need to learn this language one day (good luck Mr. Phelps!), if these repetitive tasks keep arising.
What I'd like to do is make a 1/2-baked program that does what I want, but it's too complicated.
If only I could automate the 3 things I routinely do, with pauses for user input, and screen selection of dimensions allowing user-input, then I'd be relieved of a LOT of the tedious, repetitive, stress-causing work involved w/some projects.
What I'd like to do is:
1. show on-screen all dimensions of all features w/'expression' turned on
2. simultaneously show all parameters to see if the custom/user parameters exist
3. click-on the on-screen dim I want to change, and have a tiny dialogue pop-up that allows me to enter the custom/user parameter name that links to the idw bom column.
4. have the process auto-repeat, w/esc (&tc) key termination.
That would be 'the tomcat's meow'.
Cheers ... Chris
... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 13 of 18
Anonymous
in reply to: cadman777

Quick and dirty with very little error checking, but see if this helps.


--
KWiKMcad
Kent Keller
"cadman777" wrote in message news:6377238@discussion.autodesk.com...
Mike,
Yes.
I read Brian's articles on iproperties.
They are very good (simple, concise, linear).
They remind me of the ways I used LISP in autocad.
I believe I'd need to learn this language one day (good luck Mr. Phelps!),
if these repetitive tasks keep arising.
What I'd like to do is make a 1/2-baked program that does what I want, but
it's too complicated.
If only I could automate the 3 things I routinely do, with pauses for user
input, and screen selection of dimensions allowing user-input, then I'd be
relieved of a LOT of the tedious, repetitive, stress-causing work involved
w/some projects.
What I'd like to do is:
1. show on-screen all dimensions of all features w/'expression' turned on
2. simultaneously show all parameters to see if the custom/user parameters
exist
3. click-on the on-screen dim I want to change, and have a tiny dialogue
pop-up that allows me to enter the custom/user parameter name that links to
the idw bom column.
4. have the process auto-repeat, w/esc (&tc) key termination.
That would be 'the tomcat's meow'.
Cheers ... Chris
Message 14 of 18
cadman777
in reply to: cadman777

Kent,
Thanks for the vb code.
Very slick!
That's what I want to do essentially.
It needs more work and some tweaking, like you say, but I'll try to build on it.
It's like when I used to learn from Bill Kramer:
I'd figure out what he did, and then add to and modify to suit my needs.
I wonder what % of non-programmer machine designers 'dabble' in inventor macro's?
Cheers ... Chris
... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 15 of 18
Mike.Wohletz
in reply to: cadman777

Chris
I have included the code in vb.net if you are interested in you can download the expresses edition of visual studio for free and go that route. this code could be called from a dialog box or multiple buttons or the list goes on. this is how it works:

{code}


Public Class GetMyParams
Private WithEvents m_interaction As Inventor.InteractionEvents = Nothing
Private WithEvents m_selection As Inventor.SelectEvents = Nothing
Private m_continue As Boolean = False
Private m_parameter As Inventor.DimensionConstraint = Nothing
Private m_partDoc As Inventor.PartDocument
Private m_paramName As String = Nothing

Public Sub New(ByVal partDoc As Inventor.PartDocument, ByVal paramName As String)
m_partDoc = partDoc
m_paramName = paramName

m_interaction = g_InventorApplication.CommandManager.CreateInteractionEvents

m_selection = m_interaction.SelectEvents

m_selection.AddSelectionFilter(Inventor.SelectionFilterEnum.kSketchDimConstraintFilter)

m_interaction.StatusBarText = String.Format("Select the parameter to set to {0}:", paramName)

m_interaction.Start()

End Sub

Private Sub m_selection_OnSelect(ByVal JustSelectedEntities As Inventor.ObjectsEnumerator, ByVal SelectionDevice As Inventor.SelectionDeviceEnum, ByVal ModelPosition As Inventor.Point, ByVal ViewPosition As Inventor.Point2d, ByVal View As Inventor.View) Handles m_selection.OnSelect
m_parameter = JustSelectedEntities.Item(1)

' we will change the value now
SetParameter(m_paramName, m_parameter.Parameter.Name)

m_interaction.Stop()
End Sub

Private Sub m_interaction_OnTerminate() Handles m_interaction.OnTerminate
m_partDoc = Nothing
m_parameter = Nothing
m_selection = Nothing
m_interaction = Nothing



End Sub
Public Function SetParameter(ByVal newParam As String, ByVal newValue As String) As Boolean
Dim oParams As Inventor.Parameters = m_partDoc.ComponentDefinition.Parameters
Try
Dim oParam As Inventor.Parameter = oParams.UserParameters.Item(newParam)
oParam.Expression = newValue
oParam.ExposedAsProperty = True

Catch ex As Exception
Try
Dim oparam As Inventor.Parameter = oParams.UserParameters.AddByExpression(newParam, newValue, Inventor.UnitsTypeEnum.kInchLengthUnits)
oparam.ExposedAsProperty = True

Catch exx As Exception
Return False
End Try
End Try
Return True

End Function
End Class

{code}

if you are interested in going this route let me know and I can send you my entire Visual Studio Solution for this project.

Mike
Message 16 of 18
cadman777
in reply to: cadman777

Mike,
Thanks for sharing this!
I downloaded Visual Studio Express 2010 (not that I know how to use it yet!).
I bought VisualLISP a number of years ago, and used it a lot till it got incorporated into Autocad (didn't use it much after that).
VSE seems similar, except for all the vb words not the same as lisp.
Yes, I'm interested in your entire solution for this project.
Is it available for 'trying before buying'?
Did you create this program out of personal need, or request by mechanical designers like me, or both?
Cheers ... Chris
... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 17 of 18
Mike.Wohletz
in reply to: cadman777

Chris
This is free for you to play with, I created it with your request and will probably do some modifications and make it fit my own needs. you will find that this forum is full of people that are willing to help with whatever you are working on. What I have is not perfect as I have just grabbed something that I had started and knocked the cobwebs off and added the info that you requested into it.

I will send it to you
e-mail me mwohletz at gmail dot com
Message 18 of 18
tiffany.hayden
in reply to: cadman777

Is there a way to write a macro for changing a specific hole size in a model. 

Say I have 50 parts. They all have different part numbers but their iFeature4 = .46875000 and it needs to be = .450. 

 

The manual process that I am doing at this time is. 

 

Check out - through the Vault add-in. 

Change the iFeature4  from .46875000 to .450. 

save

Check in - through the Vault add-in. 

 

 

Is it possible to automate this process using a inventor Macro? 

 

Thank you. 

 

Tiffany

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report