Create chamfer note with iLogic

Create chamfer note with iLogic

insomnix
Advocate Advocate
1,196 Views
6 Replies
Message 1 of 7

Create chamfer note with iLogic

insomnix
Advocate
Advocate

I have been using attributes to dimension drawings for a while now. For the most part it works well enough, but I'm running into a problem using the same logic to create a chamfer note. For most dimension and note methods I have to pass GeometryIntent into the method. However, the ChamferNotes.Add Method requires a DrawingCurve be passed into the method. There are no examples to compare to my code. The closest I have found is the BendNotes.Add Method, which also requires a DrawingCurve. Something isn't working correctly. Any help would be appreciated.

 

My sub call:

 

	AddChamferNote("B","CHAMFER_FACE","FLAT_FACE",5,5)

 

My procedure to easily create chamfer notes:

 

Sub AddChamferNote(View As String, Edge1 As String, Edge2 As String, Optional NoteLocationX As Double = 1, Optional NoteLocationY As Double = 1)
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
	Dim oDoc As DrawingDocument = ThisDoc.Document
	Dim oSheet As Sheet = oDoc.ActiveSheet
	Dim oView As DrawingView = ActiveSheet.View(View).View		
	' Ready code for creating of reference points
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oViewModelDoc As Document = oView.ReferencedFile.ReferencedDocument

	Dim aoEdge1 As Object
	oObjs = oViewModelDoc.AttributeManager.FindObjects(Edge1, "DIM", "1")
	aoEdge1 = oObjs.item(1)
	
	Dim aoDrawingCurve1 As DrawingCurve
	oDrawViewCurves1 = oView.DrawingCurves(aoEdge1)
	aoDrawingCurve1 = oDrawViewCurves1.item(1)

	Dim aoEdge2 As Object
	oObjs = oViewModelDoc.AttributeManager.FindObjects(Edge2, "DIM", "1")
	aoEdge2 = oObjs.item(1)
	
	Dim aoDrawingCurve2 As DrawingCurve
	oDrawViewCurves2 = oView.DrawingCurves(aoEdge2)
	aoDrawingCurve2 = oDrawViewCurves2.item(1)
	
	Dim oPosition As point2d = oTG.CreatePoint2d(NoteLocationX, NoteLocationY)
	
	Dim oChamferNote As ChamferNote
	oChamferNote = oSheet.DrawingNotes.ChamferNotes.Add(oPosition, oDrawViewCurve1, oDrawViewCurve2)
	
	oChamferNote.AttributeSets.Add("ilogic_Created")
End Sub

 

 

0 Likes
Accepted solutions (2)
1,197 Views
6 Replies
Replies (6)
Message 2 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support

@insomnix ,

 

Please provide drawing document and related model to test and make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 7

AlexFielder
Advisor
Advisor
Accepted solution

By way of debugging I made a part file using Inventor 2019.3 and named two edges of a chamfered feature (attached).

 

This rule is functionally identical to yours and it works (I'm not sure why though):

 

'this rule will attempt to look at a supplied assembly and dimensions the extents of a group of objects that are constrained together.
Sub Main()
	AddChamferNote("VIEW1", "Edge0", "Edge1", 2.5, 2.5)
End Sub


''' <summary>
''' Initially copied from this thread: 
''' https://forums.autodesk.com/t5/Inventor-customization/create-chamfer-note-With-ilogic/td-p/8646855
''' </summary>
''' <param name="View"></param>
''' <param name="Edge1"></param>
''' <param name="Edge2"></param>
''' <param name="NoteLocationX"></param>
''' <param name="NoteLocationY"></param>
Sub AddChamferNote(View As String, Edge1 As String, Edge2 As String, Optional NoteLocationX As Double = 1, Optional NoteLocationY As Double = 1)
	If Not TypeOf ThisDoc.Document Is DrawingDocument Then 
		MessageBox.Show("Not a Drawing!")
		Exit Sub
	End If
	Dim oDoc As DrawingDocument = ThisDoc.Document
	Dim oSheet As Sheet = oDoc.ActiveSheet
	Dim oView As DrawingView = ActiveSheet.View(View).View		
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oViewModelDoc As Document = oView.ReferencedFile.ReferencedDocument

	Dim aoEdge1 As Object
	oObjs = oViewModelDoc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicEntityName", Edge1)
	aoEdge1 = oObjs.Item(1)
	
	Dim aoDrawingCurve1 As DrawingCurve
	oDrawViewCurves1 = oView.DrawingCurves(aoEdge1)
	aoDrawingCurve1 = oDrawViewCurves1.Item(1)
	
	Dim points As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	Dim leaderPoint As Point2d = oTG.CreatePoint2d(aoDrawingCurve1.MidPoint.X, aoDrawingCurve1.MidPoint.Y + NoteLocationY)
	
	points.Add(leaderPoint)
	points.Add(aoDrawingCurve1.MidPoint)
	
	Dim leaderNote As LeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(points, Edge1)
	
	points.Clear

	Dim aoEdge2 As Object
	oObjs = oViewModelDoc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicEntityName", Edge2)
	aoEdge2 = oObjs.Item(1)

	Dim aoDrawingCurve2 As DrawingCurve
	oDrawViewCurves2 = oView.DrawingCurves(aoEdge2)
	aoDrawingCurve2 = oDrawViewCurves2.Item(1)
	leaderPoint = oTG.CreatePoint2d(aoDrawingCurve2.MidPoint.X, aoDrawingCurve2.MidPoint.Y + NoteLocationY)
	
	points.Add(leaderPoint)
	points.Add(aoDrawingCurve2.MidPoint)
	
	leaderNote = oSheet.DrawingNotes.LeaderNotes.Add(points, Edge2)
	
	Dim oPosition As Point2d = oTG.CreatePoint2d(aoDrawingCurve2.MidPoint.X + NoteLocationX, aoDrawingCurve2.MidPoint.Y + NoteLocationY)
	
	Dim oChamferNote As ChamferNote = oSheet.DrawingNotes.ChamferNotes.Add(oPosition, aoDrawingCurve2, aoDrawingCurve1)
	If Not oChamferNote Is Nothing Then
		oChamferNote.AttributeSets.Add("ilogic_Created")
	End If
End Sub

🙂

Message 4 of 7

insomnix
Advocate
Advocate

That helped. It looks like I had a couple mistyped variables. When I compared your code to mine I was able to find the errors. It would be nice to have some better error checking on the code, like an empty variable check that would help catch variables without values being set.

 

Thanks. I probably would have been banging my head against a wall for some time before I found the problem myself.

0 Likes
Message 5 of 7

AlexFielder
Advisor
Advisor
You can use “Option Explicit On” in the header which will do that for you. 😊
Just be aware that it is very pedantic.
0 Likes
Message 6 of 7

insomnix
Advocate
Advocate

I will try that, at least for troubleshooting. Thanks for the tip.

0 Likes
Message 7 of 7

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Just a quick reply to the old thread to include another small example in case it helps someone in the future:

'There is no iLogic function to create a chamfer note, but we can create one 
'using the API function

Dim Sheet = ThisDrawing.Sheets.ItemByName("Sheet:1") 'ilogic sheet object
Dim InvSheet = Sheet.NativeEntity 'Inventor API sheet object
Dim VIEW = Sheet.DrawingViews.ItemByName("VIEW1") 'ilogic view object
Dim InvView = VIEW.NativeEntity 'Inventor API view object

Dim Face3 = VIEW.GetIntent("Face3")
Dim Face1 = VIEW.GetIntent("Face1")

X = InvView.Center.X + InvView.Height / 2
Y = InvView.Center.Y + InvView.Width / 2
Dim PT2 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(X, Y)

'API call to create ChamferNote
Dim oChamferNote As ChamferNote
oChamferNote = InvSheet.DrawingNotes.ChamferNotes.Add(PT2, Face3.Geometry, Face1.Geometry)

 

EESignature