API Code for Creating a Drawing Dimension From Assembly Level Workpoints

API Code for Creating a Drawing Dimension From Assembly Level Workpoints

Anonymous
Not applicable
1,197 Views
3 Replies
Message 1 of 4

API Code for Creating a Drawing Dimension From Assembly Level Workpoints

Anonymous
Not applicable

High. I'm looking for a general solution to the following.

Let's say I have a given assembly document that contains some components and two workpoints. 

 

How do I turn those workpoints into GeometryIntent so that I can use them with  AddLinear and create a dim?

 

I've been working with this all day and AddLinear fails.

 

 

0 Likes
1,198 Views
3 Replies
Replies (3)
Message 2 of 4

lmc.engineering
Advocate
Advocate

Hi @Anonymous 

 

The following will add a drawing dimension to a specified view using work points found at the referenced document level.

'
Public Sub Main()
	Dim viewNo As Integer = 1
	Dim dimPt1 As String = "Work Point1"
	Dim dimPt2 As String = "Work Point2"
	Dim dimType As String = "Aligned"
	Dim dimText As String = "I made a dimension"
	Dim DimYOffset As Integer = 1
	Call AddLinearDim(viewNo, dimPt1, dimPt2, dimText, dimType,,DimYOffset)
End Sub

Private Sub AddLinearDim(viewNo As Integer,  
			dimPt1 As String, 
			dimPt2 As String, 
			dimText As String, 
			Optional dimType As String = "Aligned", 
			Optional DimXOffset As Integer = 0, 
			Optional DimYOffset As Integer = 0)
	
	Dim sDimText As String = dimText & " <DimensionValue/>"
	'Set reference to drawing document
	Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
	'Set reference to view and sheet
	Dim oView As DrawingView = oDoc.ActiveSheet.DrawingViews(viewNo)
	Dim oSheet As Sheet = oDoc.ActiveSheet

	'Get reference to document in view
	Dim viewDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim viewDocDef As ComponentDefinition = viewDoc.ComponentDefinition
	
	'Get workpoints from the assembly document
	Dim oWP1 As WorkPoint = viewDocDef.WorkPoints.Item(dimPt1)
	Dim oWP2 As WorkPoint = viewDocDef.WorkPoints.Item(dimPt2)	

	'Place Centermarks where the Work Points reside
	Dim oCM1 As Centermark = oSheet.Centermarks.AddByWorkFeature(oWP1, oView)
	Dim oCM2 As Centermark = oSheet.Centermarks.AddByWorkFeature(oWP2, oView)
	oCM1.Visible = False
	oCM2.Visible = False	

	'Create Geometry Intent of the Centermarks
	Dim oGeomIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(oCM1)
	Dim oGeomIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(oCM2)
	'Define Dimension Orientation variables
	Dim dimTypeEnum As DimensionTypeEnum = Nothing

	'Filter by dimension type
	Select Case dimType
	    Case "Vertical"
	        dimTypeEnum = 60163
	    Case "Horizontal"
	        dimTypeEnum = 60162
	    Case "Aligned"
	        dimTypeEnum = 60161
	    Case Else
	        dimTypeEnum = 60161
	End Select

	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	
	'Declare variables for dimension endpoints
	Dim oShtPt1 As Point2d = oView.ModelToSheetSpace(oWP1.Point)
	Dim oShtPt2 As Point2d = oView.ModelToSheetSpace(oWP2.Point)
	'*** Control where the Dimension Text is located
	Dim oDimX As Double = oShtPt1.X	+ DimXOffset
	Dim oDimY As Double = oShtPt1.Y + DimYOffset
	Dim oPtText As Point2d = oTG.CreatePoint2d(oDimX, oDimY)

	'*** Create the Dimension
	Dim oDimension As DrawingDimension
	oDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPtText, oGeomIntent1, oGeomIntent2, dimTypeEnum)
	oDimension.CenterText

	'Add text to dimension
	Dim MyDimText As DimensionText = oDimension.Text
	MyDimText.FormattedText = sDimText
End Sub
	 

 

Message 3 of 4

Anonymous
Not applicable

Thanks lmc!

 

One question though, where are you running the code? When I paste it into the VBA editor it squawks at the value setting portion of the Dim statements. I didn't think values could be assigned like this in VBA, but are you accomplishing this another way? I'm going through and separating the declarations and value assignments as shown in the bottom half of the image below , and then I should be able to check the code.

 

Thanks Again

 

 

Capture.JPG

0 Likes
Message 4 of 4

lmc.engineering
Advocate
Advocate

Hi,

 

It was written in vb.net to for use in an addin, but can also be used in iLogic browser too. 

As you say, separating the declarations and value assignments will do the trick, then you'll be able to run in VBA. 

 

Hopefully it does what you need

 

Thanks

0 Likes