Sketched Symbol

Sketched Symbol

dineshkumar_arumugamYY6PL
Observer Observer
85 Views
2 Replies
Message 1 of 3

Sketched Symbol

dineshkumar_arumugamYY6PL
Observer
Observer
Sub Main()
AddOrInsertPromptedSymbol()
InsertSymbolsNextToDimensions()
End Sub

Sub AddOrInsertPromptedSymbol()
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim symbolName As String = "My Symbol"
Dim found As Boolean = False

' Check if symbol definition already exists
For Each oSymbolDef As SketchedSymbolDefinition In oDoc.SketchedSymbolDefinitions
If oSymbolDef.Name = symbolName Then
found = True
Exit For
End If
Next

If found Then Return

' Create the sketched symbol definition
Dim oSymbolDefNew As SketchedSymbolDefinition = oDoc.SketchedSymbolDefinitions.Add(symbolName)
Dim oSketch As DrawingSketch = Nothing
oSymbolDefNew.Edit(oSketch)

' Draw a circle and add prompted text box in the symbol sketch
Dim oCenter As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(12, 12)
oSketch.SketchCircles.AddByCenterRadius(oCenter, 0.25)
Dim promptPlaceholder As String = "<Prompt>Enter Text</Prompt>"
Dim oTextBox As TextBox = oSketch.TextBoxes.AddFitted(oCenter, promptPlaceholder)

oSymbolDefNew.ExitEdit(True)

' Do NOT insert the symbol instance here to avoid error on first run
End Sub

Sub InsertSymbolsNextToDimensions()
Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oSymDef As SketchedSymbolDefinition

' Get the "BA" sketched symbol definition
Try
oSymDef = oDoc.SketchedSymbolDefinitions.Item("My Symbol")
Catch ex As Exception
MsgBox("Sketch Symbol 'BA' not found: " & ex.Message)
Exit Sub
End Try

Dim counter As Integer = 1
Dim offsetX As Double = 0.5
Dim offsetY As Double = 0.2
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

For Each oSheet As Sheet In oDoc.Sheets
Dim oDims As GeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions
For Each oDim As GeneralDimension In oDims
Dim dimPt As Point2d = oDim.Text.Origin
Dim symPt As Point2d = oTG.CreatePoint2d(dimPt.X + offsetX, dimPt.Y + offsetY)
Dim oLeaderPoints As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()

' Create geometry intent at the dimension location
Dim oIntent As GeometryIntent = oSheet.CreateGeometryIntent(oDim, dimPt)
oLeaderPoints.Add(symPt)
oLeaderPoints.Add(oIntent)

Dim promptValues(0) As String
promptValues(0) = counter.ToString()

Try
Dim oSketchedSymbol As SketchedSymbol = oSheet.SketchedSymbols.AddWithLeader(oSymDef, oLeaderPoints, 0, 1, promptValues)
oSketchedSymbol.Static = True
oSketchedSymbol.LeaderVisible = False
Catch ex As Exception
MsgBox("Error placing symbol " & counter & ": " & ex.Message)
End Try

counter += 1
Next
Next
End Sub

This rule -lace the sketched symbols with counter to the all dimensions. the symbol is associate to the dimension text. i use geometry intent for that. for angles it didn't place the symbol and get error, please anyone help to solve this issue.

dineshkumar_arumugamYY6PL_0-1758079733134.png

 

0 Likes
86 Views
2 Replies
Replies (2)
Message 2 of 3

b_pasupathy2000salem
Observer
Observer

I think the reason must be some dimensions creating by selecting two points instead of model edges or centerline

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor

When 'attaching' a drawing annotation with a leader to a drawing dimension type object using a GeometryIntent as one of the leader points, the Sheet.CreateGeometryIntent method provides relatively specific instructions about what is required.  The first input the method wants is the actual drawing dimension object, which is pretty simple.  However, the second input, which is normally optional, is now required.  It wants us to specify a point somewhere 'on' (not just near) the actual geometry of that dimension.  I do not believe that the origin point of the text box of the dimension qualifies in this situation.  It actually instructs us about what properties of the dimension object we can use to get the dimension's geometry objects, so we can use them to specify a point on one of those pieces of geometry as this second input.

 

One of the things it tells us we can use is the DimensionLine.  The GeneralDimension object has a ReadOnly Property named DimensionLine which returns a generic Object.  Usually that means we will need to check / test which Type of object it returns, then react accordingly, because it can return multiple different types of objects.  When the dimension actually has this line in it, its geometry should be returned by that property.  It may go without saying, but this will usually be 'linear' geometry.

 

The second two things the method tells us we can use are called ExtensionLineOne and ExtensionLineTwo.  Those are the names of Properties that we can get those objects from, but the GeneralDimension Type does not have those Properties.  The GeneralDimension Type has several sub types (derived classes) such as the AngularGeneralDimension, DiameterGeneralDimension, LinearGeneralDimension, and RadiusGeneralDimension...some of which do include those properties, as well as other properties and methods which are unique to those more specific Types.  When the dimension does have those objects, then their associated properties will likely return values representing the geometry of those objects, which can then be used to specify a point that will be 'on' the dimension.

 

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=Sheet_CreateGeometryIntent

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-GeometryIntent

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-GeneralDimension

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GeneralDimension_DimensionLine

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=LinearGeneralDimension_ExtensionLineOne

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=LinearGeneralDimension_ExtensionLineTwo

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes