ADD QUANTITY TO CHAMFER NOTE

ADD QUANTITY TO CHAMFER NOTE

hieut1392
Enthusiast Enthusiast
425 Views
4 Replies
Message 1 of 5

ADD QUANTITY TO CHAMFER NOTE

hieut1392
Enthusiast
Enthusiast

I wrote code that adds quantity to radius, but my code doesn't work when applied to chamfer note.

Any pro can help me edit this code? My code is below. I am using Inventor 2016.

 

 

Screenshot 2022-12-15 161211.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Function AddQuantityToRadius(x As String)

On Error GoTo Leave

Repeat:

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

Dim selection As Object
Set selection = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingDefaultFilter, "Select radius or ESC to cancel")

If (Not selection Is Nothing) Then
     selection.Text.FormattedText = x & "-" & selection.Text.FormattedText
    GoTo Repeat:
End If

Leave:

End Function

 

 

 

 

 

0 Likes
426 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @hieut1392.  Unfortunately, there is no online help for the FormattedText of a ChamferNote object, plus a ChamferNote object has a Text property, a FormattedChamferNote property, and a regular FormattedText property, so figuring out the right one to work with, and the right way to format the final value may have to be done by reverse engineering it.  What I mean by reverse engineering is, modify the note manually to look the way you want it to, then use a very simple iLogic rule to retrieve its FormattedText contents, and show it to you...hopefully in a selectable & copy-able way, such as with an InputBox (instead of MsgBox), but put the value in the 'DefaultResponse' section, so that will be in the editable text box when it shows.  Then you can copy/paste it into your text editor, review it, and paste it back into your rule for setting the values that way from now on.  Below is a simple example, similar to yours, but in iLogic/vb.net, instead of VBA.

 

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	'Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	AddQtyToChanferNote("3")
End Sub

Sub AddQtyToChanferNote(oQty As String) 'Sub, because not returning anything
	Repeat :
	oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingNoteFilter, "Select a Chanfer Note.")
	If IsNothing(oObj) OrElse (TypeOf oObj Is ChamferNote = False) Then Exit Sub 'Return Nothing
	Dim oCNote As ChamferNote = oObj
	Try : oCNote.FormattedChamferNote = oQty & "-" & oCNote.FormattedChamferNote : Catch : End Try
	GoTo Repeat
End Sub

 

Edit:  Also, I looked within the Styles Editor dialog, at a Dimension style, over under its Notes and Leaders tab, selected the chamfer note icon, and I only see 3 possible 'smart' input options there (Distance 1, Distance 2, and Angle).  So, no chance of a 'smart' quantity in there, to be able to do it a more proper way.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

hieut1392
Enthusiast
Enthusiast

thanks for your help. But with "kDrawingNoteFilter" i can't choose Chamfer Note. I tried with other filters but the result is still the same.

 

 

Option Explicit

Sub MainAddQuantityChamferNote()

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
    MsgBox ("A Drawing Document must be active for this rule to work. Exiting.")
        Exit Sub
    End If
    
    AddQtyToChanferNote ("3")
    
End Sub

Sub AddQtyToChanferNote(oQty As String) 'Sub, because not returning anything

Repeat:

Dim oObj As Object

Set oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingNoteFilter, "Select a Chanfer Note.")
    
    If oObj Is Nothing Then Exit Sub 'Return Nothing
    
    Dim oCNote As ChamferNotes
    Set oCNote = oObj
    
    oCNote.FormattedChamferNote = oQty & "-" & oCNote.FormattedChamferNote
   
    GoTo Repeat
    
End Sub

 

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

Hi @hieut1392.  You were right about the selection filter.  It does not make sense to me though, because in the Inventor API Object Model, the ChamferNote object is found directly under DrawingNotes, so that should include anything under it.  This time I added a real chamfer to a part, then added a real ChamferNote to that feature on the drawing, so I had something to test my code on.  The FormattedChamferNote property returned a really long, and complicated String, full of lots of XML code, and lots of tolerance specs, even though there were no tolerances shown on the drawing.  When I tried adding "3 x " text to the beginning of that, it resulted in some really odd-looking results, so I moved on to testing out the regular FormattedText property.  That one was much simpler looking inside (only contained "<ChamferNote/>"), and when I did the same thing to that one, it worked just as expected.  I modified my code a bit to include the InputBox routine I mentioned, just so you can see what I saw, but you can totally get rid of that bit of code afterwards, and just add the text to the start of that FormattedText, similar to what it is doing now, but without the help of the InputBox part.

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	'Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	AddQtyToChanferNote("3 x ")
End Sub

Sub AddQtyToChanferNote(oQty As String) 'Sub, because not returning anything
	Repeat :
	oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingDefaultFilter, "Select a Chanfer Note.")
	If IsNothing(oObj) OrElse (TypeOf oObj Is ChamferNote = False) Then Exit Sub 'Return Nothing
	Dim oCNote As ChamferNote = oObj
	Dim oFText As String = InputBox("Edit FText", "FormattedText", oCNote.FormattedText)
	Try : oCNote.FormattedText = oFText : Catch : End Try
	'Try : oCNote.FormattedText = oQty & oFText : Catch : End Try
	GoTo Repeat
End Sub

Be careful copying though, I noticed in your VBA version of this code, that you are using the plural Type (ChamferNotes) when declaring your variable, instead of the singular Type (ChamferNote), which won't work.  By the way, I highly recommend that you focus more of your Inventor automation focus on developing solutions with either iLogic or vb.net (iLogic uses vb.net as its basis), instead of VBA, because VBA has security problems, which is why Autodesk has stopped including the VBA Editor in any new installations of Inventor starting with 2021 version (Link).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

hieut1392
Enthusiast
Enthusiast

i ran your code from iLogic browser, still can't pick the chamfer note.  

0 Likes