Move sketch symbol off center y direction

Move sketch symbol off center y direction

Formsprag
Advocate Advocate
737 Views
6 Replies
Message 1 of 7

Move sketch symbol off center y direction

Formsprag
Advocate
Advocate

Hi Forum,

 

I have adapted some code for locating a sketch symbol on the center of a view; however I need to move it off center in the y direction and nothing I do works, any ideas?

 

Sub Main()
'	DeleteSymbols()
	
	PlaceClutchRotationSymbol("FRONT VIEW","Clutch Rotation (Input End)")
'	PlaceDriveSymbol("TOP VIEW","INPUT END (DRIVE)")
'	PlaceDrivenSymbol("TOP VIEW"," OUTPUT END (DRIVEN)")
End Sub

' Add symbols to show grain direction on a view
Sub PlaceClutchRotationSymbol(viewName As String, symbolName As String)
	Dim drawDoc As DrawingDocument
	drawDoc = ThisApplication.ActiveDocument
	
	Dim sheet As Sheet
	sheet = drawDoc.ActiveSheet
	
	Dim symbolDef As SketchedSymbolDefinition
	symbolDef = drawDoc.SketchedSymbolDefinitions.Item(symbolName)
				
	' Select a drawing view.
        Dim drawingView As DrawingView
        drawingView = ActiveSheet.View(viewName).View
	
	' Get center of the view to place the symbol
	Dim symbolCenter As Point2d = drawingView.Center
	' If it is the Front view, move the center of the symbol so it displays centered on the face of the part
	If viewName = "Front View" Then
		symbolCenter.X = symbolCenter.X - ActiveSheet.View(viewName).Scale * .75
		symbolCenter.Y = symbolCenter.Y - ActiveSheet.View(viewName).Scale * .4
	End If
	
	' Default scale is 1
	Dim symbolScale As Double = 1
	
	Dim sketchedSymbol As SketchedSymbol
	sketchedSymbol = sheet.SketchedSymbols.Add(symbolDef, symbolCenter, symbolRotation, symbolScale)
	sketchedSymbol.Static = True
End Sub

I need this;
2020-08-06_5-25-37.jpg

I get this;
2020-08-06_5-25-57.jpg
0 Likes
Accepted solutions (2)
738 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

I don't know where within your sketched symbol you have the insertion point (you can specify this when creating them), but maybe this will work better for you.

Sub Main()
	PlaceClutchRotationSymbol("FRONT VIEW","Clutch Rotation (Input End)")
End Sub

Sub PlaceClutchRotationSymbol(viewName As String, symbolName As String)
	Dim oDDoc As DrawingDocument = ThisDrawing.Document
	Dim oSheet As Sheet = oDDoc.ActiveSheet
	Dim oSDef As SketchedSymbolDefinition = oDDoc.SketchedSymbolDefinitions.Item(symbolName)
	Dim oView As DrawingView = oSheet.DrawingViews.Item(viewName)
	Dim oCPoint As Point2d = oView.Center
	Dim oVWidth As Double = oView.Width
	Dim oVHeight As Double = oView.Height
	Dim oSymInsPoint As Point2d
	' If it is the Front view, move the center of the symbol so it displays centered on the face of the part
	If viewName = "Front View" Then
		oSymInsPoint = ThisApplication.TransientGeometry.CreatePoint2d(oCPoint.X - (oVWidth/8), oCPoint.Y - (oVHeight/2))
	Else
		oSymInsPoint = oCPoint.Copy
	End If
	Dim oRotation As Double = 0
	Dim oScale As Double = 1
	Dim oSymbol As SketchedSymbol = oSheet.SketchedSymbols.Add(oSDef, oSymInsPoint, oRotation, oScale)
	oSymbol.Static = True
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

Formsprag
Advocate
Advocate

Returns the following:

 

2020-08-06_7-20-00.jpg

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor
Accepted solution

I've seen this before, for some reason it doesn't recognize the view name string in place of the index integer, as you can normally do.  So I switched setting the value of oView to a loop which searches all the views for one with that name, then checks to see that it found something afterwords.

Sub Main()
	PlaceClutchRotationSymbol("FRONT VIEW","Clutch Rotation (Input End)")
End Sub

Sub PlaceClutchRotationSymbol(viewName As String, symbolName As String)
	Dim oDDoc As DrawingDocument = ThisDrawing.Document
	Dim oSheet As Sheet = oDDoc.ActiveSheet
	Dim oSDef As SketchedSymbolDefinition = oDDoc.SketchedSymbolDefinitions.Item(symbolName)
	Dim oView As DrawingView
	For Each oDView As DrawingView In oSheet.DrawingViews
		If oDView.Name = viewName Then oView = oDView
	Next
	If oView Is Nothing Then
		MsgBox("It couln't find a drawing view named " & viewName & ". Exiting.", vbOKOnly, " ")
		Return
	End If
	Dim oCPoint As Point2d = oView.Center
	Dim oVWidth As Double = oView.Width
	Dim oVHeight As Double = oView.Height
	Dim oSymInsPoint As Point2d
	' If it is the Front view, move the center of the symbol so it displays centered on the face of the part
	If viewName = "Front View" Then
		oSymInsPoint = ThisApplication.TransientGeometry.CreatePoint2d(oCPoint.X - (oVWidth/8), oCPoint.Y - (oVHeight/2))
	Else
		oSymInsPoint = oCPoint.Copy
	End If
	Dim oRotation As Double = 0
	Dim oScale As Double = 1
	Dim oSymbol As SketchedSymbol = oSheet.SketchedSymbols.Add(oSDef, oSymInsPoint, oRotation, oScale)
	oSymbol.Static = True
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

Formsprag
Advocate
Advocate

This code didn't return any errors but it still placed the symbol on the center of the view.

 

I did however take your advice and change the insertion point on my symbol. Brilliant, I didn't think of that!

 

Thanks!

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Hmmm... It must have failed the If...Else...End If test that checks the views name.  I did notice that the supplied view name in your last post was in all capitol letters, and the value later in the Sub was not, so maybe it is case sensitive.  It should have created a Point2d that was 1/8 of the views width to the left of center, and 1/2 of the views height below center.

I know that the sizes within the code are in centimeters, by default (I don't know if you are working with metric or imperial units), instead of document units, but since I was dealing purely with percentages/fractions, it shouldn't have mattered enough to not be visibly away from the center of the view.

Maybe try getting rid of the that whole view name check would force it to use the new coordinates.

Try this.

Sub Main()
	PlaceClutchRotationSymbol("FRONT VIEW","Clutch Rotation (Input End)")
End Sub

Sub PlaceClutchRotationSymbol(viewName As String, symbolName As String)
	Dim oDDoc As DrawingDocument = ThisDrawing.Document
	Dim oSheet As Sheet = oDDoc.ActiveSheet
	Dim oSDef As SketchedSymbolDefinition = oDDoc.SketchedSymbolDefinitions.Item(symbolName)
	Dim oView As DrawingView
	For Each oDView As DrawingView In oSheet.DrawingViews
		If oDView.Name = viewName Then oView = oDView
	Next
	If oView Is Nothing Then
		MsgBox("It couln't find a drawing view named " & viewName & ". Exiting.", vbOKOnly, " ")
		Return
	End If
	oView.p
	Dim oCPoint As Point2d = oView.Center
	Dim oVWidth As Double = oView.Width
	Dim oVHeight As Double = oView.Height
	Dim oSymInsPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oCPoint.X - (oVWidth/8), oCPoint.Y - (oVHeight/2))
	Dim oRotation As Double = 0
	Dim oScale As Double = 1
	Dim oSymbol As SketchedSymbol = oSheet.SketchedSymbols.Add(oSDef, oSymInsPoint, oRotation, oScale)
	oSymbol.Static = True
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 7

Formsprag
Advocate
Advocate

Worked Perfect as soon as I removed: 

oView.p

 Thank you!

0 Likes