Error after running leader annotation rule

Error after running leader annotation rule

emilda.chiuye
Enthusiast Enthusiast
435 Views
6 Replies
Message 1 of 7

Error after running leader annotation rule

emilda.chiuye
Enthusiast
Enthusiast

Hello.

I am trying to run this leader annotated text for a drawing however, I come across this error.

Please assist in figuring out what "Public member 'Sheet'on type'_DocumentClass'not found " means.

emildachiuye_0-1628311720177.png

Here is the code, 

 

Sub Main AddLeaderNote()
    
     Dim oDrawDoc As DrawingDocument = ThisDoc.Document 'then no need to reference the drawing document. Either or)    
'Reference this drawing sheet
	Dim DrawSheet As Sheet = oDrawDoc.Sheet("STANDARD SUPERHEATER DWG")
'Reference this drawing view
	  Dim oView As DrawingView
	  oView = ActiveSheet.View("FRONT ELEVATION").View 
	 
    Dim oDrawingCurveSegment As DrawingCurveSegment
     oDrawingCurveSegment = oDrawDoc.SelectSet.Item(1)

    Dim oDrawingCurve As DrawingCurve
     oDrawingCurve = oDrawingCurveSegment.Parent

    Dim oMidPoint As Point2d
     oMidPoint = oDrawingCurve.MidPoint

    Dim oTG As TransientGeometry
     oTG = ThisApplication.TransientGeometry

    Dim oLeaderPoints As ObjectCollection
     oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection
'Create a few leader points.
     oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 10))
     oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 5))

'Create an intent and add to the leader points collection.
'This is the geometry that the leader text will attach to.
     Dim oGeometryIntent = DrawSheet.CreateGeometryIntent("User Parameters,FCW1_AT_TUBEC")
'Select dimension text position
     Dim textOrigin = DrawSheet

     oLeaderPoints.Add(oGeometryIntent)

    Dim sText As String
    sText = "API Leader Note"

    Dim oLeaderNote As LeaderNote
     'oLeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add("A1 Landscape:1" )
     ActiveSheet = ThisDrawing.Sheet("A1 Landscape:1")
	 
    Dim oFirstNode As LeaderNode
     oFirstNode = oLeaderNote.Leader.RootNode.ChildNodes.Item(1)

    Dim oSecondNode As LeaderNode
     oSecondNode = oFirstNode.ChildNodes.Item(1)

    Call oFirstNode.InsertNode(oSecondNode, oTG.CreatePoint2d(oMidPoint.X + 5, oMidPoint.Y + 5))
End Sub

 

 

0 Likes
436 Views
6 Replies
Replies (6)
Message 2 of 7

A.Acheson
Mentor
Mentor

Th error is here. 

 

Dim DrawSheet As Sheet = oDrawDoc.Sheet("STANDARD SUPERHEATER DWG")

You are attempting to look for a single sheet by its name in the active document without first looking in the collection of sheets.

A tip if you have declared the sheet type in  oDrawDoc.(and then type sheet) nothing will come up as a tool tip as the sheet is not the collection. Where as when you have the correct collection the tooltip will appear explaining it's functionality.

 

AAcheson_0-1628327687929.png

 

You can get DrawSheet by a few methods

Dim DrawSheet As Sheet = oDrawDoc.Sheets.Item("STANDARD SUPERHEATER DWG")

Or

Dim DrawSheet As Sheet = oDrawDoc.Sheets("STANDARD SUPERHEATER DWG")

Or

The correct ilogic method should be like this 

DrawSheet = ThisDrawing.Sheet(“sheetname”)

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 7

emilda.chiuye
Enthusiast
Enthusiast

Thank you so much for this educative assistance!

I now run the code and it says the parameter is incorrect.

emildachiuye_0-1628329190126.png

This is the parameter I am trying to refer to 

emildachiuye_1-1628329213041.png

Which line in the code is incorrectly referenced or worded? I am able to refer to these pre-defined parameters manually though. 

   Dim oLeaderPoints As ObjectCollection
     oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection
'Create a few leader points.
     oLeaderPoints.Add(oTG.CreatePoint2d("User Parameters,FCW1_AT_TUBEC"))
     oLeaderPoints.Add(oTG.CreatePoint2d("User Parameters,FCW2_AT_TUBEC"))

'Create an intent and add to the leader points collection.
'This is the geometry that the leader text will attach to.
     Dim oGeometryIntent As GeometryIntent

'Select dimension text position
     Dim textOrigin = DrawSheet

     oLeaderPoints.Add(oGeometryIntent)

    Dim sText As String
    sText = "API Leader Note"

    Dim oLeaderNote As LeaderNote
     'oLeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add("A1 Landscape:1" )
     ActiveSheet = ThisDrawing.Sheet("A1 Landscape:1")
	 
    Dim oFirstNode As LeaderNode
     oFirstNode = oLeaderNote.Leader.RootNode.ChildNodes.Item(1)

    Dim oSecondNode As LeaderNode
     oSecondNode = oFirstNode.ChildNodes.Item(1)

    Call oFirstNode.InsertNode(oSecondNode, oTG.CreatePoint2d("User Parameters,FCW1_AT_TUBEC"))
End Sub

 

0 Likes
Message 4 of 7

emilda.chiuye
Enthusiast
Enthusiast

If there is no solution to the 2D annotation then I would greatly appreciate assistance on the 3D annotation instead.

With the help of @Ralf_Krieg  this shorter 3D annotation rule works however my issue is with line 9, you see previously there was a command Manager that prompted me to "select a face" and all I wish is for the leader to be set to a feature in the model tree so that when I run the code the annotation will pop up pointing to Revolved Feature1 for example and so on. So should I suppress this features then so too does the 3D leader annotation.

 

Regards

Dim oDoc As Inventor.PartDocument = ThisDoc.Document
Dim oDef As Inventor.PartComponentDefinition = oDoc.ComponentDefinition
Dim oTG As Inventor.TransientGeometry = ThisApplication.TransientGeometry

Dim oRepMan As Inventor.RepresentationsManager = oDef.RepresentationsManager
Dim oDesignViewReps As Inventor.DesignViewRepresentations = oRepMan.DesignViewRepresentations

Dim oFace As Inventor.Face = FeaDture.IsActive("Revolved Feature1")
Dim oAnnoPlaneDef As Inventor.AnnotationPlaneDefinition = oDef.ModelAnnotations.CreateAnnotationPlaneDefinitionUsingPlane(oDef.WorkPlanes(2))
Dim oLeaderPoints As Inventor.ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

oLeaderPoints.Add(oTG.CreatePoint(1, 0,1))

Dim oLeaderIntent As Inventor.GeometryIntent = oDef.CreateGeometryIntent("FCW1 AT TUBE C ")
oLeaderPoints.Add(oLeaderIntent)
Dim oLeaderDef As Inventor.ModelLeaderNoteDefinition = oDef.ModelAnnotations.ModelLeaderNotes.CreateDefinition(oLeaderPoints, "2000", oAnnoPlaneDef)
Dim oLeader As Inventor.ModelLeaderNote = oDef.ModelAnnotations.ModelLeaderNotes.Add(oLeaderDef)

 

0 Likes
Message 5 of 7

A.Acheson
Mentor
Mentor

What is the end goal with placing this annotation? Do you want to place it on a specific part or to inject the user parameter into the text of the leader?

 

A few pictures of the manually created leader and what they are attaching too. If this is an assembly drawing you will likely need to attach the leader to a named face in a part as assembly named faces are not supported as of yet. 

 

This post here is working with assembly drawing leaders

https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/leader-text-on-an-assembly-edge/td-p/63...

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 6 of 7

emilda.chiuye
Enthusiast
Enthusiast

I would like to achieve differentiating between new and and existing items on the tube, and yes they (3D leader annotations) should be attached to a parameter which I have set already. There are a number of these revolved features however they need to be called out with different names/numbers as they vary from new to existing.

I have attached a snippet of it accomplished manually. So when one or more of these features are hidden so will the annotation that goes along with it. In the meantime let me peruse this link you sent, see if I can make sense of it....

emildachiuye_0-1628452603133.png

Parameters to which the annotations should be set.  Not sure of my statement but is it not easier to set this up in the model environment then all I do is retrieve these dimensions in idw as others on this forum have previously done.

emildachiuye_1-1628452917146.png

 

 

0 Likes
Message 7 of 7

Ralf_Krieg
Advisor
Advisor

Hello

 

Hopefully I understand what happens when.

You have a part wih one or more revolve feature(s). The features unique named to identify them. You have one or more user parameter in your part. There is an relation between the revolve feature name and the parameter namer. I assume the feature and the corresponding parameter have same name.

 

There seem's to be an error in current Inventor release (2022.1) . If the model annotation with a linked user parameter is deleted, the user parameter is also deleted.

 

 

Private Sub Main()
    
    Dim oApp As Inventor.Application= ThisApplication
    Dim oDoc As Inventor.PartDocument= oApp.ActiveDocument
    Dim oDef As Inventor.PartComponentDefinition= oDoc.ComponentDefinition
    Dim oTG As Inventor.TransientGeometry= oApp.TransientGeometry
    Dim oRepMan As Inventor.RepresentationsManager= oDef.RepresentationsManager
    Dim oDesignViewReps As Inventor.DesignViewRepresentations= oRepMan.DesignViewRepresentations
    Dim oOuterFace As Inventor.Face
    Dim oRevolveFeature As Inventor.RevolveFeature

    For Each oRevolveFeature In oDef.Features.RevolveFeatures
        If Feature.IsActive(oRevolveFeature.Name) And oRevolveFeature.HealthStatus = HealthStatusEnum.kUpToDateHealth Then
            If CheckExistLeader(oRevolveFeature) = False Then
                oOuterFace = GetOuterFace(oRevolveFeature)
                
                Dim oAnnoPlaneDef As Inventor.AnnotationPlaneDefinition= oDef.ModelAnnotations.CreateAnnotationPlaneDefinitionUsingPlane(oDef.WorkPlanes(2))
                Dim oLeaderPoints As Inventor.ObjectCollection= oApp.TransientObjects.CreateObjectCollection
                Dim oIntentPoint As Point
                
                Select Case oOuterFace.SurfaceType
                Case SurfaceTypeEnum.kConeSurface:
                    oIntentPoint = GetPointOnCone(oOuterFace)
                Case SurfaceTypeEnum.kCylinderSurface:
                    oIntentPoint = GetPointOnCylinder(oOuterFace)
                End Select
                 
                Dim oLeaderIntent As Inventor.GeometryIntent= oDef.CreateGeometryIntent(oOuterFace, oIntentPoint)
                'The Leaderpoint should be relative positioned to the LeaderPoint 1
                Call oLeaderPoints.Add(oTG.CreatePoint(oIntentPoint.X + 1, 0, oIntentPoint.Z + 1))
                Call oLeaderPoints.Add(oLeaderIntent)

				Dim sFormattedText As String
                sFormattedText = "NaN"
                
                Dim oLeaderDef As Inventor.ModelLeaderNoteDefinition = oDef.ModelAnnotations.ModelLeaderNotes.CreateDefinition(oLeaderPoints, sFormattedText, oAnnoPlaneDef)
                
                Dim oLeader As Inventor.ModelLeaderNote= oDef.ModelAnnotations.ModelLeaderNotes.Add(oLeaderDef)
                
				oLeader.Definition.Text.FormattedText = GetParamValue(oRevolveFeature)
				
                oOuterFace = Nothing
            End If
        End If
    Next
End Sub

Private Function CheckExistLeader(ByVal oRevolveFeature As RevolveFeature) As Boolean
    Dim oPartCompDef As PartComponentDefinition = oRevolveFeature.Parent
    Dim oLeaderNotes As ModelLeaderNotes = oPartCompDef.ModelAnnotations.ModelLeaderNotes
	Dim oFace As Face
    Dim oIntentFace As Face
    Dim oLeaderNote As ModelLeaderNote
    
	For Each oLeaderNote In oLeaderNotes
		oIntentFace = oLeaderNote.Definition.Intent.Geometry
		For Each oFace In oRevolveFeature.Faces
			If oIntentFace Is oFace Then
				Return True
			End If
		Next
    Next
End Function

Private Function GetOuterFace(ByVal oRevolveFeature As Inventor.RevolveFeature) As Inventor.Face
    Dim oFace As Inventor.Face
    Dim oOuterFace As Inventor.Face
    For Each oFace In oRevolveFeature.Faces
        If oFace.SurfaceType = SurfaceTypeEnum.kConeSurface Or oFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
            If Not oOuterFace Is Nothing Then
                If oFace.Geometry.Radius > oOuterFace.Geometry.Radius Then
                    oOuterFace = oFace
                End If
            Else
                oOuterFace = oFace
            End If
        End If
    Next
	GetOuterFace = oOuterFace
End Function

Private Function GetPointOnCone(ByVal oFace As Face) As Point
    Dim oCone As Cone= oFace.Geometry
    Dim oSB As SurfaceBody= oFace.SurfaceBody
    Dim oBasis As Point = oCone.BasePoint
    Dim oRadius As Double = oCone.Radius
    Dim oEnts As Inventor.ObjectsEnumerator
    Dim oPoints As Inventor.ObjectsEnumerator
    Dim oVector As Vector= ThisApplication.TransientGeometry.CreateVector(0, 1, 0)
    
    Call oSB.FindUsingRay(oBasis, oVector.AsUnitVector, oRadius, oEnts, oPoints, False)
    
    If oEnts.Count > 0 Then
        Dim i As Integer
        For i = 1 To oEnts.Count
            If oEnts(i) Is oFace Then
                GetPointOnCone = oPoints(i)
            End If
        Next
    End If
End Function

Private Function GetPointOnCylinder(ByVal oFace As Face) As Point
    Dim oCylinder As Cylinder= oFace.Geometry
    Dim oSB As SurfaceBody= oFace.SurfaceBody
    Dim oBasis As Point = oCylinder.BasePoint
    Dim oRadius As Double= oCylinder.Radius
    Dim oEnts As Inventor.ObjectsEnumerator
    Dim oPoints As Inventor.ObjectsEnumerator
    Dim oVector As Vector = ThisApplication.TransientGeometry.CreateVector(0, 1, 0)
    
    Call oSB.FindUsingRay(oBasis, oVector.AsUnitVector, oRadius, oEnts, oPoints, False)
    
    If oEnts.Count > 0 Then
        Dim i As Integer
        For i = 1 To oEnts.Count
            Call ThisApplication.ActiveDocument.SelectSet.Select(oEnts(i))
            Select Case oEnts(i).Type
            Case kVertexObject:
            Case kEdgeObject:
                Dim oEdge As Edge= oEnts(i)
                Dim oConFace As Face
                For Each oConFace In oEdge.Faces
                    If oConFace Is oFace Then
                        GetPointOnCylinder = oPoints(i)
                    End If
                Next
            Case kFaceObject:
                GetPointOnCylinder = oPoints(i)
            End Select
        Next
    End If
End Function

Private Function GetParamValue(ByVal oRevolveFeature As RevolveFeature) As String
    GetParamValue = "NaN"
    
    Dim oPartDoc As PartDocument= oRevolveFeature.Parent.Document
    
    Dim oUserParam As UserParameter
    For Each oUserParam In oPartDoc.ComponentDefinition.Parameters.UserParameters
        If oRevolveFeature.Name = oUserParam.Name Then
            GetParamValue = "<Parameter Resolved='True' ComponentIdentifier='" & oPartDoc.FullFileName & "' Name='" & oUserParam.Name & "' Precision='" & oUserParam.Precision & "'>" & oUserParam.Value & "</Parameter>"
            Exit For
        End If
    Next
End Function

 

 

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes