Creating a Dimension between two workplanes in a drawing

Creating a Dimension between two workplanes in a drawing

Anonymous
Not applicable
2,120 Views
5 Replies
Message 1 of 6

Creating a Dimension between two workplanes in a drawing

Anonymous
Not applicable

Hello everybody,

 

i'm about to create a fully automated drawing sheet. Until now I used WorkPoints for dimensions in the drawing. But now i want to add a Dimension between two WorkPlanes.

I tried to modify the code for my WorkPoints to make it suitable...

Here is the code i use for my WorkPoints:

Dim oSheet As Sheet = ThisDoc.Document.ActiveSheet
Dim oView As DrawingView = ActiveSheet.View("ANSICHT1").View
Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oGeomIntent1 As Inventor.GeometryIntent
Dim oGeomIntent2 As Inventor.GeometryIntent
Dim oWP1 As Inventor.WorkPoint = oDoc.ComponentDefinition.WorkPoints(1)'.Item("WP_1")
Dim oWP2 As Inventor.WorkPoint = oDoc.ComponentDefinition.WorkPoints(2)'.Item("WP_2")
oView.SetIncludeStatus(oWP1, True)
oView.SetIncludeStatus(oWP2, True)
Dim oCenterMark1 As Inventor.Centermark
Dim oCenterMark2 As Inventor.Centermark
Dim oCenterMark As Inventor.Centermark
For Each oCenterMark In oSheet.Centermarks
If oCenterMark.Attached Then
If oCenterMark.AttachedEntity Is oWP1 Then
oCenterMark1 = oCenterMark
End If
If oCenterMark.AttachedEntity Is oWP2 Then
oCenterMark2 = oCenterMark
End If
End If
Next
oGeomIntent1 = oSheet.CreateGeometryIntent(oCenterMark1, kPoint2dIntent)
oGeomIntent2 = oSheet.CreateGeometryIntent(oCenterMark2, kPoint2dIntent)
oCenterMark1.Visible = False
oCenterMark2.Visible = False
Dim textPoint1 As Inventor.Point2d = ThisServer.TransientGeometry.CreatePoint2d(27.5,25)
Dim textPoint2 As Inventor.Point2d = ThisServer.TransientGeometry.CreatePoint2d(44,25)
Dim oDim1 as GeneralDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(textPoint1, oGeomIntent1, oGeomIntent2, DimensionTypeEnum.kHorizontalDimensionType)
Dim oDim2 as GeneralDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(textPoint2, oGeomIntent1, oGeomIntent2, DimensionTypeEnum.kVerticalDimensionType)

 

This code so far works fine, but when i modify it i get the error message:

 

System.Runtime.InteropServices.COMException (0x80004005): unknown error (Exception from HRESULT: 0x80004005 (E_FAIL))

at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)

at Inventor.GeneralDimensions.AddLinear(Point2d TextOrigin, GeometryIntent IntentOne, Object IntentTwo, DimensionTypeEnum DimensionType, Boolean ArrowheadsInside, Object DimensionStyle, Object Layer)

at LmiRuleScript.Main()

at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)

at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Here is the part of the code i want to use for my WorkPlanes:

 

Dim oGeomIntent5 As Inventor.GeometryIntent
Dim oGeomIntent6 As Inventor.GeometryIntent
Dim oWP5 As Inventor.WorkPlane = oDoc.ComponentDefinition.WorkPlanes("XZ Plane")
Dim oWP6 As Inventor.WorkPlane = oDoc.ComponentDefinition.WorkPlanes("Work Plane1")
oView.SetIncludeStatus(oWP5, True)
oView.SetIncludeStatus(oWP6, True)
oGeomIntent5 = oSheet.CreateGeometryIntent(oWP5, kStartPointIntent)
oGeomIntent6 = oSheet.CreateGeometryIntent(oWP6, kEndPointIntent)
Dim textPoint4 As Inventor.Point2d = ThisServer.TransientGeometry.CreatePoint2d(20,25)
Dim oDim4 as GeneralDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(textPoint4, oGeomIntent5, oGeomIntent6, DimensionTypeEnum.kVerticalDimensionType)

i never saw an example of an dimension-code between two workplanes so i tried out a lot of modifications, but there was always this error message i mentioned...

 

Does someone has experience with this type of dimensions?

 

thanks in advance,

 

Lorenz

0 Likes
2,121 Views
5 Replies
Replies (5)
Message 2 of 6

wayne.brill
Collaborator
Collaborator

Hi Lorenz,

 

I believe that CreateGeometryIntent does not support WorkPlanes. This is from the programming help. Geometry is the first argument: 

>> >>

Geometry:

Input object that specifies the geometry. Valid \input objects are DrawingCurve, sketch entities from a sheet sketch, DrawingDimension, Centerline, and Centermark objects.

<< <<

 

You could request an enhancement for it on the Inventor Idea station.

http://forums.autodesk.com/t5/inventor-ideastation/idb-p/v1232/tab/most-recent

 

It seems to me there would need to be a way to determine the points on the plane to use.

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 6

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi Lorenz,

 

Please find the following solution for your issue. Please free to contact if you have any doubts.

 

public void Create_Dimensions_Planes()

        {

            DrawingDocument oDoc = mApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,

                                                      mApp.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject,

                                                        SystemOfMeasureEnum.kDefaultSystemOfMeasure,

                                                        DraftingStandardEnum.kDefault_DraftingStandard,

                                                        null),

                                                      true) as DrawingDocument;

 

            Sheet oSheet = oDoc.Sheets.Add(DrawingSheetSizeEnum.kBDrawingSheetSize,

                                           PageOrientationTypeEnum.kDefaultPageOrientation,

                                           "A Size", 0, 0);

           

            

            PartDocument oBlockPart = mApp.Documents.Open(@"Part/Assembly document location", false) as PartDocument;

 

            TransientGeometry oTG = mApp.TransientGeometry;

 

            WorkPlane wp1 = oBlockPart.ComponentDefinition.WorkPlanes["Work Plane name1"];

            wp1.AutoResize = true;

            WorkPlane wp2 = oBlockPart.ComponentDefinition.WorkPlanes["Work Plane name2"];

            wp2.AutoResize = true;

           

            DrawingView oBaseView = oSheet.DrawingViews.AddBaseView(oBlockPart as _Document,

                                                                    oTG.CreatePoint2d(10, 10), 1,

                                                                    ViewOrientationTypeEnum.kFrontViewOrientation,

                                                                    DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "", null, null);          

 

           

 

 

            Centerline line1 = oSheet.Centerlines.AddByWorkFeature(wp1, oBaseView);

            Centerline line2 = oSheet.Centerlines.AddByWorkFeature(wp2, oBaseView);

 

            GeometryIntent wInt1 = oSheet.CreateGeometryIntent(line1, PointIntentEnum.kStartPointIntent);

            GeometryIntent wInt2 = oSheet.CreateGeometryIntent(line2, PointIntentEnum.kStartPointIntent);

 

            GeneralDimensions oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions;

 

            Point2d oDimPos = oTG.CreatePoint2d(line1.StartPoint.X - 2, line1.StartPoint.Y);

 

            DimensionStyle dimstyle = oDoc.StylesManager.DimensionStyles["Default (ANSI)"];

 

            Layer layer = oDoc.StylesManager.Layers["Dimension (ANSI)"];

 

            //Create the dimension.

            LinearGeneralDimension oLinearDim;

            oLinearDim = oGeneralDimensions.AddLinear(oDimPos, wInt1, wInt2,

                                                      DimensionTypeEnum.kAlignedDimensionType, true,

                                                      dimstyle,

                                                      layer);

        }

 

Thanks and regards,

Chandra shekar Gopal.


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 6

keithjk
Advocate
Advocate

Chandra shekar Gopal,

 

I tried converting your code to .NET and am having some problems.  Please see my code below and the attached screen shot of the error.

 

Any ideas?


Thanks,

Keith

 

 

 

 Dim oDrawingDocument As DrawingDocument
        oDrawingDocument = oInventorApp.ActiveDocument
        oSheet = oInventorApp.ActiveDocument.ActiveSheet
        oDrawingView = oInventorApp.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter,
                                                        "Select a view to place dimension(s) on.")

        oAssemblyDocument = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
        oTG = oInventorApp.TransientGeometry

        GetEnclosurePartNumber()

        Dim wp1 As WorkPlane = oEnclosure.Definition.WorkPlanes.Item("WP_Top")
        wp1.AutoResize = True
        Dim wp2 As WorkPlane = oEnclosure.Definition.WorkPlanes.Item("WP_Bottom")
        wp2.AutoResize = True

        Dim centerLine1 As Centerline = Nothing
        Dim centerline2 As Centerline = Nothing
        centerLine1 = oSheet.Centerlines.AddByWorkFeature(wp1, oDrawingView)
        centerline2 = oSheet.Centerlines.AddByWorkFeature(wp2, oDrawingView)

        Dim wInt1 As GeometryIntent = oSheet.CreateGeometryIntent(centerLine1, PointIntentEnum.kStartPointIntent)
        Dim wInt2 As GeometryIntent = oSheet.CreateGeometryIntent(centerline2, PointIntentEnum.kStartPointIntent)

        Dim oDimPos As Point2d = oTG.CreatePoint2d(centerLine1.StartPoint.X - 2, centerline2.StartPoint.Y)

        Dim oDim As GeneralDimension = Nothing
        oDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oDimPos, wInt1, wInt2, DimensionTypeEnum.kAlignedDimensionType)

 

 

0 Likes
Message 5 of 6

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi Keith,

 

I have gone through your code. In order to create dimension between work planes, creation of centerline is very important here.

 

Centerlines can be created easily with workplanes of  referenced assembly or referenced part to Drawing document. But unable to create centerlines for occurrences of workplanes of referenced assembly.

 

One more noticed point is that, if work planes are perpendicular to drawing view. Then also centerlines can not be created. I tried manually also.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 6

s.alaviJR58M
Explorer
Explorer

Hi Keith,

You can most definitely create centerlines from workplanes of occurrences. Also you can create centerlines from workplanes which are perpendicular to the view. See code below.

 

<<The code needs to be run in an assembly environment. It creates a 2d drawing on runtime and add views. Then for the base view it cycles through all the occurrences and creates a centerline for each YZ Plane in the part.>>

 

Dim omodel As AssemblyDocument
omodel = ThisApplication.Documents.Item(1)
Dim odoc As DrawingDocument
''odoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "\\192.168.0.251\InvSet2019\Templates\Standard.dwg", True)
odoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "C:\Users\s.alavi\OneDrive - MPS Systems BV\Documenten\Sales Configurator\Standard.dwg", True)
Dim osheet As Sheet
osheet = odoc.Sheets.Item(1)

Dim opoint As Point2d
opoint = ThisApplication.TransientGeometry.CreatePoint2d(osheet.Width/2, osheet.Height/2)
Dim oview As DrawingView
oview = osheet.DrawingViews.AddBaseView(omodel, opoint, 0.05, kFrontViewOrientation, kHiddenLineRemovedDrawingViewStyle)

If oview.Height > 0.4 * osheet.Height Then
oview.Scale = oview.Scale / 1.25
Else If oview.Height < 0.2 * osheet.Height Then
oview.Scale = oview.Scale * 1.25
End If

If oview.Width > 0.95 * osheet.Width Then
oview.Scale = oview.Scale / 1.25
Else If oview.Height < 0.475 * osheet.Height Then
oview.Scale = oview.Scale * 1.25
End If

opoint = ThisApplication.TransientGeometry.CreatePoint2d(osheet.Width / 2, oview.Height / 2 + osheet.Width / 7)

oview.Position = opoint

Dim oBorder As Border
oBorder = osheet.Border

Dim oPlacementPoint As Point2d

oPlacementPoint = oBorder.RangeBox.MaxPoint

Dim oPartsList As PartsList
oPartsList = osheet.PartsLists.Add(oview, oPlacementPoint)

Dim oview2 As DrawingView

opoint.Y = opoint.Y + 1.50 * oview.Height

oview2 = osheet.DrawingViews.AddProjectedView(oview, opoint, kHiddenLineRemovedDrawingViewStyle)

Dim oDrawAss As AssemblyDocument
oDrawAss = oview.ReferencedDocumentDescriptor.ReferencedDocument

Dim oOcc As ComponentOccurrences
oOcc = oDrawAss.ComponentDefinition.Occurrences

Dim i As Integer

Dim oWP As WorkPlane
Dim oWPP As WorkPlaneProxy
Dim oWP2 As WorkPlane
Dim oWPP2 As WorkPlaneProxy
Dim oCL1 As Centerline
Dim oCL2 As Centerline

For i = 1 To oOcc.Count - 1
oWP = oOcc.Item(i).Definition.WorkPlanes.Item(1)
Call oOcc.Item(i).CreateGeometryProxy(oWP, oWPP)
oCL1 = osheet.Centerlines.AddByWorkFeature(oWPP,oview)
oWP2 = oOcc.Item(i+1).Definition.WorkPlanes.Item(1)
Call oOcc.Item(i+1).CreateGeometryProxy(oWP2, oWPP2)
oCL2 = osheet.Centerlines.AddByWorkFeature(oWPP2, oview)
opoint = ThisApplication.TransientGeometry.CreatePoint2d(0.5 * (oCL1.StartPoint.X + oCL2.StartPoint.X), oCL1.EndPoint.Y - 2)
Dim oGInt1 As GeometryIntent = osheet.CreateGeometryIntent(oCL1)
Dim oGInt2 As GeometryIntent = osheet.CreateGeometryIntent(oCL2)
Dim oDim As GeneralDimension = osheet.DrawingDimensions.GeneralDimensions.AddLinear(opoint, oGInt1, oGInt2)
Next