Create drawing dimensions using work features within subcomponent

Create drawing dimensions using work features within subcomponent

mat_hijs
Collaborator Collaborator
707 Views
3 Replies
Message 1 of 4

Create drawing dimensions using work features within subcomponent

mat_hijs
Collaborator
Collaborator

I'm trying to automate creating some dimensions for my drawings. I got to the point where I can dimension a part using the workplanes  in that part. Now I'm trying to get to the next step which is placing these same dimensions when this part is placed in an assembly. I think I'm almost there, but I can't get the last step, actually creating the dimension, to work. Could anyone help me out on this one?

Here's my code:

 

Dim oDoc As DrawingDocument
	oDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
	oSheet = oDoc.ActiveSheet

Dim oDrawingViews As DrawingViews

Dim oDrawingView As DrawingView
	oDrawingView = ActiveSheet.View("VIEW1").View
	
Dim oModelAsm As AssemblyDocument
	oModelAsm = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument

Dim oModelAsmCompDef As AssemblyComponentDefinition
	oModelAsmCompDef = oModelAsm.ComponentDefinition

Dim oModelPart As ComponentOccurrence
	oModelPart = oModelAsmCompDef.Occurrences.ItemByName("Profiel")

Dim oModelPartDoc As PartDocument
	oModelPartDoc = oModelPart.Definition.Document

Dim oModelPartCompDef As PartComponentDefinition
	oModelPartCompDef = oModelPartDoc.ComponentDefinition

Dim oOnderkant As WorkPlane
	oOnderkant = oModelPartCompDef.WorkPlanes.Item("WPL_Onderkant")
Dim oBovenkant As WorkPlane
	oBovenkant = oModelPartCompDef.WorkPlanes.Item("WPL_Bovenkant")

Dim oOnderkantIntent As GeometryIntent
	oOnderkantIntent = oSheet.CreateGeometryIntent(oOnderkant)
Dim oBovenkantIntent As GeometryIntent
	oBovenkantIntent = oSheet.CreateGeometryIntent(oBovenkant)

Dim oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions

Dim oPointX As Double
	oPointX = -2
Dim oPointY As Double
	oPointY = 0

Dim oPoint As Point2d
	oPoint = ThisServer.TransientGeometry.CreatePoint2d(oPointX, oPointY)

MsgBox("This is where I stop working.")

Dim oLinearDimLengte = oGeneralDims.AddLinear(oPoint, oOnderkantIntent, oBovenkantIntent)

0 Likes
Accepted solutions (1)
708 Views
3 Replies
Replies (3)
Message 2 of 4

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

The workplanes of your part are represented by a workplaneproxy object in assembly context. So you first have to create this proxy objects to "walk" in the right context.

The included workplanes/workplaneproxys are displayed as centerlines on sheet. So you need to create a geometryintent for these centerlines to attach your dimension to.

 

Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oDrawingViews As DrawingViews
Dim oDrawingView As DrawingView= ActiveSheet.View("VIEW1").View
Dim oModelAsm As AssemblyDocument = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oModelAsmCompDef As AssemblyComponentDefinition = oModelAsm.ComponentDefinition
Dim oModelPart As ComponentOccurrence = oModelAsmCompDef.Occurrences.ItemByName("Profiel")
Dim oModelPartDoc As PartDocument = oModelPart.Definition.Document
Dim oModelPartCompDef As PartComponentDefinition = oModelPartDoc.ComponentDefinition

Dim oOnderkant As WorkPlane = oModelPartCompDef.WorkPlanes.Item("WPL_Onderkant")
Dim oBovenkant As WorkPlane = oModelPartCompDef.WorkPlanes.Item("WPL_Bovenkant")

Dim oOnderkantProxy As WorkPlaneProxy
Call oModelPart.CreateGeometryProxy(oOnderkant, oOnderkantProxy)

Dim oBovenkantProxy As WorkPlaneProxy
Call oModelPart.CreateGeometryProxy(oBovenkant, oBovenkantProxy)

Dim oOnderkantIntent As GeometryIntent
Dim oBovenkantIntent As GeometryIntent
Dim oCenterline As Centerline
For Each oCenterline In oSheet.Centerlines
    If oCenterline.ModelWorkFeature Is oOnderkantProxy Then
        oOnderkantIntent = oSheet.CreateGeometryIntent(oCenterline)
    ElseIf oCenterline.ModelWorkFeature Is oBovenkantProxy Then
        oBovenkantIntent = oSheet.CreateGeometryIntent(oCenterline)
    End If
Next

Dim oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions

Dim oPointX As Double = -2
Dim oPointY As Double = 0
Dim oPoint As Point2d = ThisServer.TransientGeometry.CreatePoint2d(oPointX, oPointY)

'MsgBox("This is where I stop working.")

Dim oLinearDimLengte = oGeneralDims.AddLinear(oPoint, oOnderkantIntent, oBovenkantIntent, DimensionTypeEnum.kAlignedDimensionType, True)

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 4

JelteDeJong
Mentor
Mentor

I think you need to use WorkPlaneProxy's in stead of WorkPlanes when you create intents from a assembly. I could not test this code but i expect that it will work:

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet

Dim oDrawingViews As DrawingViews

Dim oDrawingView As DrawingView
oDrawingView = ActiveSheet.View("VIEW1").View

Dim oModelAsm As AssemblyDocument
oModelAsm = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument

Dim oModelAsmCompDef As AssemblyComponentDefinition
oModelAsmCompDef = oModelAsm.ComponentDefinition

Dim oModelPart As ComponentOccurrence
oModelPart = oModelAsmCompDef.Occurrences.ItemByName("Profiel")

Dim oModelPartDoc As PartDocument
oModelPartDoc = oModelPart.Definition.Document

Dim oModelPartCompDef As PartComponentDefinition
oModelPartCompDef = oModelPartDoc.ComponentDefinition

Dim oOnderkant As WorkPlane
oOnderkant = oModelPartCompDef.WorkPlanes.Item("WPL_Onderkant")
Dim oBovenkant As WorkPlane
oBovenkant = oModelPartCompDef.WorkPlanes.Item("WPL_Bovenkant")

' Create proxy work planes
Dim oOnderkantProxy As WorkPlaneProxy = Nothing
oModelPart.CreateGeometryProxy(oOnderkant, oOnderkantProxy)
Dim oBovenkantProxy As WorkPlaneProxy = Nothing
oModelPart.CreateGeometryProxy(oBovenkant, oBovenkantProxy)

' use the proxy work planes instead of the original workplanes
Dim oOnderkantIntent As GeometryIntent
oOnderkantIntent = oSheet.CreateGeometryIntent(oOnderkantProxy)
Dim oBovenkantIntent As GeometryIntent
oBovenkantIntent = oSheet.CreateGeometryIntent(oBovenkantProxy)

Dim oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions

Dim oPointX As Double
oPointX = -2
Dim oPointY As Double
oPointY = 0

Dim oPoint As Point2d
oPoint = ThisServer.TransientGeometry.CreatePoint2d(oPointX, oPointY)

MsgBox("This is where I stop working.")

Dim oLinearDimLengte = oGeneralDims.AddLinear(oPoint, oOnderkantIntent, oBovenkantIntent)

On a side note if you are using Inventor 2021 or later there are build in functions that do a great job in creating dimensions for parts. For Assemblies those functions do not work but in my blog i write how you can create your own functions.

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 4 of 4

mat_hijs
Collaborator
Collaborator

I had some issues running your code, but after a while I found that the workplanes have to be included in the view first, after I did this it worked perfectly. I added a couple of lines that include the workplanes and then makes the centerlines invisible. After that I transformed the whole thing into a function so I can call the function, enter 2 workplanes and leave the rest for the function to figure out. Next up: automating the creation of breaks 😄

Thanks for your help!

0 Likes