Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Macro Add thickness + trailing Zeros

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
amartin.r
651 Views, 9 Replies

Macro Add thickness + trailing Zeros

Hi,

 

What code allow to create a macro button with :

In parameters :

- Check : Thickness

- Check : Trailing zeros (in "Custom property format")

config-projet-vault.png

 

Thanks,

9 REPLIES 9
Message 2 of 10
mrattray
in reply to: amartin.r

Try this:

 

Dim oDoc As Document
Dim oSheetMetalCompDef As SheetMetalComponentDefinition
Dim oParam As Parameter
Dim oParamFormat As CustomPropertyFormat

oDoc = ThisDoc.Document

If oDoc.DocumentType <> kPartDocumentObject Then
	MsgBox("This rule is only valid for part documents.", vbOKOnly, "Error")
	Exit Sub
End If

Try
	oSheetMetalCompDef = oDoc.ComponentDefinition
Catch
	Try
		oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
		oSheetMetalCompDef = oDoc.ComponentDefinition
	Catch
		MsgBox("Part must be a sheet metal part. Please click the Convert Part to Sheet Metal button!",vbOKOnly,"Error")
		Exit Sub
	End Try
End Try

Try
	oParam = oSheetMetalCompDef.Parameters.ModelParameters.Item("Thickness")
	oParam.ExposedAsProperty = True
	oParamFormat = oParam.CustomPropertyFormat
	oParamFormat.ShowUnitsString = False
	oParamFormat.ShowLeadingZeros = False
	oParamFormat.ShowTrailingZeros = True
	oParamFormat.Precision = kThreeDecimalPlacesPrecision
Catch
	MsgBox("Failure to format: Thickness", vbOKOnly, "Error")
End Try

 

You can change the value of each true false statement to suite your needs. It should be self explanatory.

Mike (not Matt) Rattray

Message 3 of 10
amartin.r
in reply to: mrattray

Thank you for your reactivity,

But the macro is blocking at :
Pop-up "Compile error: Invalid use of property"
"oDoc ="

Message 4 of 10
mrattray
in reply to: amartin.r

This is written for iLogic. It sounds like you're trying to use this in the API. They use different languages. Can you use it as iLogic?
Mike (not Matt) Rattray

Message 5 of 10
amartin.r
in reply to: mrattray

I would like to use this macro only sometimes, and don't to depend of one rule in a file.

Message 6 of 10
mrattray
in reply to: amartin.r

If you save it as an external rule you can call it at will from the iLogic browser without having to add it to your files.
Mike (not Matt) Rattray

Message 7 of 10
amartin.r
in reply to: mrattray

It's working with some modifications

 

oParam = oSheetMetalCompDef.Parameters.ModelParameters.Item("Epaisseur")
oParam.ExposedAsProperty = True
oParamFormat = oParam.CustomPropertyFormat
oParamFormat.ShowUnitsString = False
oParamFormat.ShowLeadingZeros = False
oParamFormat.ShowTrailingZeros = True

 

I deleted the last msgbox because the box shows "Error", then there is no error !

 

Thank you !

 

Just for my information, what advantage to use iLogic rather than "VBA" ?

Message 8 of 10
mrattray
in reply to: amartin.r

Sorry, I missed that you were using a different language than English. If you're getting the error message, than I would be concerned that one of the lines in the property formatting is not getting executed for some reason or another. Can you test and verify that it's actually changing each format option?

 

iLogic is a little easier to run directly from Inventor (in my opinion, anyways), but more significantly it offers some .NET functionality (like the Try Catch statements I used here) that is not available using traditional VBA in the API.

Mike (not Matt) Rattray

Message 9 of 10

Hi amartin.r,

 

Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Message 10 of 10
amartin.r
in reply to: mrattray

This msgBox appears same there is no problem for execute the code.

Error.png

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

Post to forums  

Autodesk Design & Make Report