Inventor General Discussion

Inventor General Discussion

Reply
Contributor
nkeeley
Posts: 17
Registered: ‎10-15-2012
Message 1 of 7 (234 Views)
Accepted Solution

Bend angle macro decimal point (VBA)

234 Views, 6 Replies
12-11-2013 08:53 AM

Hi all. I have a short macro to add the compliment angle to all the bend angles on an Inventor 2014 drawing. I want it to always show one decimal point on the compliment angle, but if that would be '0' then it doesn't show it. I.e. in the attached picture I want it to be 58.0 (122.0) DOWN. I've attached the code here. Anybody have a suggestion?

 

Thanks!

Nathan

 

 

Sub Test()
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oView As DrawingView
    Set oView = oDoc.ActiveSheet.DrawingViews(1)
    
    Dim oNewDimStyle As DimensionStyle
    Set oNewDimStyle = oDoc.StylesManager.DimensionStyles.Item("RASOR")
    
    Dim oNote As BendNote
    Dim sTemp()  As String
    Dim sTemp1() As String
    Dim iAngle As Double
    
    For Each oNote In oDoc.ActiveSheet.DrawingNotes
        If oNote.Type = kBendNoteObject Then
            sTemp = Split(oNote.Text, " ")
            
            For i = 0 To UBound(sTemp)
                If InStr(sTemp(i), "°") > 0 Then
                    iAngle = CDbl(Split(sTemp(i), "°")(0))
                    
                    If InStr(oNote.FormattedBendNote, "(") > 0 Then
                        sTemp1 = Split(oNote.FormattedBendNote, "(")
                        oNote.FormattedBendNote = Replace(oNote.FormattedBendNote, Split(sTemp1(1), ")")(0), CStr(180 - iAngle))
                        oNote.DimensionStyle = oNewDimStyle
            
                    Else
                        oNote.FormattedBendNote = Replace(oNote.FormattedBendNote, "</BendAngle>", "</BendAngle>" & "(" & CStr(180 - iAngle) & ")")
                        oNote.DimensionStyle = oNewDimStyle
                    End If
                    Exit For
                End If
            Next
        End If
    Next
End Sub

*Expert Elite*
cwhetten
Posts: 1,071
Registered: ‎09-03-2008
Message 2 of 7 (222 Views)

Re: Bend angle macro decimal point (VBA)

12-11-2013 09:51 AM in reply to: nkeeley

It seems to me that this would be controlled by your dimension style called "RASOR".  You would need to edit the RASOR dim style and set the angular dimension precision to 1.1 and turn on the option for trailing zeros:

 

Angle Dimension Trailing Zeroes.PNG

 

This would best be done in your template, but you could perhaps write some additional lines of code to modify the dim style.

 

Cameron Whetten
Inventor 2014

Contributor
nkeeley
Posts: 17
Registered: ‎10-15-2012
Message 3 of 7 (216 Views)

Re: Bend angle macro decimal point (VBA)

12-11-2013 10:04 AM in reply to: cwhetten

Cameron,

Thanks for the reply. My RASOR style is already setup exactly like you show. Honestly, I was hoping I forgot to check the trailing zeros box, but that doesn't seem to be it.

 

Nathan

*Expert Elite*
cwhetten
Posts: 1,071
Registered: ‎09-03-2008
Message 4 of 7 (207 Views)

Re: Bend angle macro decimal point (VBA)

12-11-2013 10:32 AM in reply to: nkeeley

Hi Nathan.  Can you repost the image from your first post, but in higher resolution?  I can't read it.  This is what I see:

 

What I See.png

 

It would help me understand exactly what your code is doing.

 

Thanks.

 

Cameron Whetten
Inventor 2014

Contributor
nkeeley
Posts: 17
Registered: ‎10-15-2012
Message 5 of 7 (202 Views)

Re: Bend angle macro decimal point (VBA)

12-11-2013 10:42 AM in reply to: cwhetten

Sorry about that. Let's see if this one is any better.

*Expert Elite*
cwhetten
Posts: 1,071
Registered: ‎09-03-2008
Message 6 of 7 (190 Views)

Re: Bend angle macro decimal point (VBA)

12-11-2013 01:29 PM in reply to: nkeeley

OK, I figured something out.

 

Instead of the Cstr( ) function, use the Format( ) function.  So, for each instance of CStr(180 - iAngle) in your code, replace it with Format(180 - iAngle, "###.0").

 

I tested it and it seemed to work.  Give it a try and post back.

 

Cameron Whetten
Inventor 2014

Please click "Accept as Solution" if this response answers your question.

Contributor
nkeeley
Posts: 17
Registered: ‎10-15-2012
Message 7 of 7 (183 Views)

Re: Bend angle macro decimal point (VBA)

12-11-2013 02:11 PM in reply to: cwhetten

Worked perfect. Thanks!

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.