Insert Sketch Symbol using ilogic on center of gravity

Insert Sketch Symbol using ilogic on center of gravity

omvcilindri
Contributor Contributor
2,137 Views
6 Replies
Message 1 of 7

Insert Sketch Symbol using ilogic on center of gravity

omvcilindri
Contributor
Contributor

Hi

I would like to insert the sketch symbol using ilogic on the center of gravity

but I don't understand where the error is

 

Pt = iProperties.CenterOfGravity
centerPt = iProperties.CenterOfGravity
'CBWeightCG = centerPt.y
'CBWeightCG = centerPt.x
cx = pt.X
cy = pt.Y
cz = pt.Z

Dim oDrawDoc As DrawingDocument = ThisDrawing.Document

' Obtain a reference to the desired sketched symbol definition.
Dim oSketchedSymbolDef As SketchedSymbolDefinition _
= oDrawDoc.SketchedSymbolDefinitions.Item("baricentro")

Dim oSheet As Sheet = oDrawDoc.ActiveSheet

'create insertion point, coordinates - in cm !
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
''questa funziona--- this in ok
'Dim oInsertionPoint As Point2d = oTG.CreatePoint2d(10, 10)

Dim oPosition As Point2d : oPosition = iProperties.CenterOfGravity
oPosition.Y = pt.Y
oPosition.X = pt.X
Dim oInsertionPoint As Point2d = oTG.Type(centerPt)

Dim oSketchedSymbol As SketchedSymbol _
= oSheet.SketchedSymbols.Add( _
oSketchedSymbolDef, _
oInsertionPoint, _
0, 1, Nothing)

 

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

WCrihfield
Mentor
Mentor

Are you trying to place your SketchedSymbol at the Center point of a view within your drawing sheet, or are you trying to place it at the center of the drawing sheet, or find the actual Center of Gravity of the ModelDocument of this DrawingDocument within a certain view?

Because, looking at your code, if you have a Drawing Document open and active, you are first trying to get the Center of Gravity from the Drawing Document's iProperties, which isn't going to work.  You can get that from the ModelDocument if you want, but I'm not sure how that's going to help you within the drawing.

The following code assums you want to place your SketchedSymbol at the center point of a specific view (in this case, the first view within the active drawing sheet.

Dim oDdoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet = oDdoc.ActiveSheet
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
Dim oViewCenter As Point2d = oView.Center
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oInsertPoint As Point2d = oTG.CreatePoint2d(oViewCenter.X, oViewCenter.Y)

Dim oSkSymDef As SketchedSymbolDefinition = oDdoc.SketchedSymbolDefinitions.Item("baricentro")
Dim oSkSym As SketchedSymbol = oSheet.SketchedSymbols.Add(oSkSymDef, oInsertPoint, 0, 1)

I kept the name of your SketchedSymbolDefinition as "baricentro", and kept your options within the insertion statement, except for the "Nothing" at the end, because those last three options within that statement are 'optional', meaning you don't have to specify them to make the statement function.

I hope this helps.

If this solves your problem or answers your question, please click 'Accept As Solution'.

Or if this helps you along the way to reaching your goal, please click 'Like'.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 7

omvcilindri
Contributor
Contributor

thank you very much for your answer, what I would like to do is insert my
symbol on the center of gravity, if you know how the correct code should be,
you can indicate it please

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

This has turned out to be a more difficult task than I first assumed it would be.

First of all, after a lot of searching around, I don't think the ability to turn that Center of Gravity feature on and off for a specific drawing view in a drawing is available yet.  I do know how to execute the basic command, using the Command Manager, but I have not figured out how to specify that I only want this command to effect that one specific Drawing View within the Drawing Document yet.   I've seen a few ideas for work-arounds to accomplish similar things, though.

One option was:

Using code...Get the Model Document that the drawing is referencing, create a WorkPoint at the center of mass within the model file.  I know how to do that part.  Then on the drawing side, include that WorkPoint in the specified View.  This part is a bit more tricky. I'm almost certain it can be done, but I've been very busy lately, so I haven't had that much time to work on this for you.

I've posted below what I've got so far.  The portion of the code that doesn't have the ' marks in front of it, will place the sketched symbol, into the drawing without creating a point within your Model file, but it still doesn't seem to be placing it where we want it.  You can give it a try if you'd like.

Dim oDdoc As DrawingDocument = ThisDrawing.Document
Dim oSkSymDef As SketchedSymbolDefinition = oDdoc.SketchedSymbolDefinitions.Item("OBSOLETE")
Dim oSheet As Sheet = oDdoc.ActiveSheet
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oInsertPoint As Point2d
Dim oSkSym As SketchedSymbol
'Dim oCOGbutton As ButtonDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("AppCenterOfGravityCmd")

Dim oModelCOM As Point
Dim oWPoint As WorkPoint
Dim oExists As Boolean = False
If ThisDrawing.ModelDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	Dim oMAdoc As AssemblyDocument = ThisDrawing.ModelDocument
	Dim oACompDef As AssemblyComponentDefinition = oMAdoc.ComponentDefinition
	oModelCOM = oACompDef.MassProperties.CenterOfMass
'	For Each oWP As WorkPoint In oACompDef.WorkPoints
'		If oWP.Name = "Center Of Mass" Then
'			oWP.SetFixed(oModelCOM)
'			oExists = True
'		End If
'	Next
'	If oExists = False Then
'		oWPoint = oACompDef.WorkPoints.AddFixed(oModelCOM, True)
'		oWPoint.Name = "Center Of Mass"
'	End If
'	Somehow 'Include' that WorkPoint named "Center Of Mass" in the View
	
	oInsertPoint = oTG.CreatePoint2d(oView.ModelToDrawingViewSpace(oModelCOM).X,oView.ModelToDrawingViewSpace(oModelCOM).Y)
	oSkSym = oSheet.SketchedSymbols.Add(oSkSymDef, oInsertPoint)
ElseIf ThisDrawing.ModelDocument.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	Dim oMPdoc As PartDocument = ThisDrawing.ModelDocument
	Dim oPCompDef As PartComponentDefinition = oMPdoc.ComponentDefinition
	oModelCOM = oPCompDef.MassProperties.CenterOfMass
'	For Each oWP As WorkPoint In oPCompDef.WorkPoints
'		If oWP.Name = "Center Of Mass" Then
'			oWP.SetFixed(oModelCOM)
'			oExists = True
'		End If
'	Next
'	If oExists = False Then
'		oWPoint = oPCompDef.WorkPoints.AddFixed(oModelCOM, True)
'		oWPoint.Name = "Center Of Mass"
'	End If
'	Somehow 'Include' that WorkPoint named "Center Of Mass" in the View
	oInsertPoint = oTG.CreatePoint2d(oView.ModelToDrawingViewSpace(oModelCOM).X,oView.ModelToDrawingViewSpace(oModelCOM).Y)
	oSkSym = oSheet.SketchedSymbols.Add(oSkSymDef, oInsertPoint)
End If


 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

JelteDeJong
Mentor
Mentor
Accepted solution

You could try running this code and select a drawing view.

Dim doc As DrawingDocument = ThisApplication.ActiveDocument
Dim sheet As Sheet = doc.ActiveSheet
Dim view As DrawingView = ThisApplication.CommandManager.Pick(
	SelectionFilterEnum.kDrawingViewFilter, "Select a drawing view.")

Dim CoG As Centermark = sheet.Centermarks.AddByCenterOfGravity(view)

Dim oSketchedSymbolDef As SketchedSymbolDefinition = doc.SketchedSymbolDefinitions.Item("CoG")
Dim oSketchedSymbol As SketchedSymbol = sheet.SketchedSymbols.Add(
	oSketchedSymbolDef, CoG.Position, 0, 1, Nothing)

My sketched symbol is called CoG. You might need to change it to the name you used.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 6 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Thanks.  That works for my test drawing.  I didn't think about going the Centermark route.  It already had that built-in method for accessing that CenterOfGravity Property, which isn't even listed as a property of the View within the DrawingView Object's refference help file.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 7

omvcilindri
Contributor
Contributor

thank you very much it is an excellent solution

0 Likes