Class Not Registered Error When Adjusting Text Style
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have created the following iLogic to mark part numbers onto a face. It runs pretty reliably except for the first time I run it in a part. When I do that I get an "unknown error" on line 108 when I try to adjust the text alignment. If I comment out any point where I adjust that alignment, it will run successfully. I can then un-comment out those lines and it runs without issue. Some other experimentation and investigation also gives an occasional "class not registered" error when trying to adjust text style alignment.
Looking for help on how/why this is happening, or other workarounds.
Dim oPartDoc As Inventor.PartDocument
Dim bPart As Boolean
Dim msg
'In-Place Edit Check
If ThisApplication.ActiveDocumentType = kpartDocumentObject Then
oPartDoc = ThisApplication.ActiveDocument
bPart = True
Else If ThisApplication.ActiveDocumentType = kAssemblyDocumentObject And ThisApplication.ActiveEditDocument.DocumentType = kpartDocumentObject Then
oPartDoc = ThisApplication.ActiveEditDocument
bPart = False
Else
sDocType = ThisApplication.ActiveEditDocument.DocumentType.ToString
msg = MessageBox.Show("No part file selected for edit", "No Part for Edit", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
Exit Sub
End If
Dim oCompDef As Inventor.PartComponentDefinition = oPartDoc.ComponentDefinition
Dim oTransGeom As Inventor.TransientGeometry = ThisApplication.TransientGeometry
Dim oSketchAxis As Inventor.Edge
Dim oSketchFace As Inventor.Face
Dim oCornerPoint As Inventor.Point
'Get reference geometry
If Not bPart Then
Dim oPickFace As Inventor.FaceProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Surface to Place Text")
Dim oPickVertex As Inventor.VertexProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartVertexFilter, "Select Corner for Text")
oSketchFace = oPickFace.NativeObject
oCornerPoint = oPickVertex.NativeObject.Point
Else
Dim oPickFace As Inventor.Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Surface to Place Text")
Dim oPickVertex As Inventor.Vertex = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartVertexFilter, "Select Corner for Text")
oSketchFace = oPickFace
oCornerPoint = oPickVertex.Point
End If
'Set outer edge loop
Dim oEdgeLoop As Inventor.EdgeLoop
If oSketchFace.EdgeLoops.Count > 1 Then
For i = 1 To oSketchFace.EdgeLoops.Count
If oSketchFace.EdgeLoops.Item(i).IsOuterEdgeLoop Then
oEdgeLoop = oSketchFace.EdgeLoops.Item(i)
End If
Next
Else
oEdgeLoop = oSketchFace.EdgeLoops.Item(1)
End If
Dim edge1 As Inventor.Edge
Dim edge2 As Inventor.Edge
Dim curve1Eval As CurveEvaluator
Dim curve2Eval As CurveEvaluator
Dim maxP As Double
Dim minP As Double
Dim curveLength1 As Double
Dim curveLength2 As Double
Dim osketchAxisLength As Double
'set default sketch x axis
oSketchAxis = oEdgeLoop.Edges.Item(1)
curve1Eval = oSketchAxis.Evaluator
Call curve1Eval.GetParamExtents(minP,maxP)
Call curve1Eval.GetLengthAtParam(minP, maxP, osketchAxisLength)
Dim maxEdges = oSketchFace.Edges.Count
'set/check longest edge as x axis
For i = 1 To maxEdges
edge1 = oEdgeLoop.Edges.Item(i)
If i >= maxEdges Then
edge2 = oEdgeLoop.Edges.Item(i)
Else
edge2 = oEdgeLoop.Edges.Item(i + 1)
End If
curve1Eval = edge1.Evaluator
curve2Eval = edge2.Evaluator
Call curve1Eval.GetParamExtents(minP,maxP)
Call curve1Eval.GetLengthAtParam(minP, maxP, curveLength1)
Call curve2Eval.GetParamExtents(minP, maxP)
Call curve2Eval.GetLengthAtParam(minP, maxP, curveLength2)
If curveLength1 > curveLength2 And curveLength1 > osketchAxisLength Then
oSketchAxis = edge1
End If
Next
'set middle point of face
Dim oMinPt As Inventor.Point = oEdgeLoop.RangeBox.MinPoint
Dim oMaxPt As Inventor.Point = oEdgeLoop.RangeBox.MaxPoint
Dim oCtPoint As Inventor.Point = oTransGeom.CreatePoint((oMaxPt.X + oMinPt.X) / 2#, (oMaxPt.Y + oMinPt.Y) / 2#, (oMaxPt.Z + oMinPt.Z) / 2#)
'draw sketch
Dim oSketch As Inventor.PlanarSketch = oCompDef.Sketches.AddWithOrientation(oSketchFace, oSketchAxis, True, True, oSketchAxis.StartVertex)
Dim oPoint As Inventor.Point2d = oSketch.ModelToSketchSpace(oCornerPoint)
Dim oPointRef As Inventor.Point2d = oSketch.ModelToSketchSpace(oCtPoint)
Dim dOffset As Double = (0.25 * 2.54)
Dim oStyle As Inventor.TextStyle = oPartDoc.TextStyles.Item("MARK")
oStyle.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter 'fails here
oStyle.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
'determine which way to offset text
If oPointRef.X > oPoint.X Then
oPoint.X += dOffset
oStyle.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft
Else
oPoint.X -= dOffset
oStyle.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextRight
End If
If oPointRef.Y > oPoint.Y Then
oPoint.Y += dOffset
oStyle.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextLower
Else
oPoint.Y -= dOffset
oStyle.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextUpper
End If
'PN textbox
Dim sText As String = iProperties.Value("Project", "Part Number")
oSketch.TextBoxes.AddFitted(oPoint, sText, oStyle)
Dim oSketchObjects As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oSketchText As Inventor.TextBox
For Each oSketchText In oSketch.TextBoxes
oSketchObjects.Add(oSketchText)
Next
'mark text onto face
Dim oMarkDef As MarkDefinition = oCompDef.Features.MarkFeatures.CreateMarkDefinition(oSketchObjects, oPartDoc.MarkStyles.Item(1))
Dim oMark As MarkFeature = oCompDef.Features.MarkFeatures.Add(oMarkDef)