Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Drawing dimension/attribute help.

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
herrwolf1
3473 Views, 11 Replies

Drawing dimension/attribute help.

Hello,
From a VB.Net program, I'm trying to create a dimension on a drawing document between two parts in an assembly. I can get the parts using component occurrence. The line marked below throws the following error: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)). As you may see, I have allocated memory for both "Edge" and "Face" (Dim oEdge1 As Face) albeit one is commented out. Attached is the screen shots from the attribute helper add-in. In it, you will notice that the attributes are of type: "Face". What am I doing wrong? Any help and especially code examples would be greatly appreciated.

Eric


{code}
Public Sub CreateDrawingDimension(ByVal Part1 As String, ByVal Part2 As String, ByVal AttName1 As String, ByVal AttName2 As String)
' Get the Active Drawing document
Dim oDrawDoc As Inventor.DrawingDocument
oDrawDoc = invApp.ActiveDocument

' Get the active sheet
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet

Dim oDrawView As Inventor.DrawingView
oDrawView = oDrawDoc.ActiveSheet.DrawingViews.Item(1)

' Get the assembly shown in the view.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = oDrawView.ReferencedDocumentDescriptor.ReferencedDocument

Dim oOccurrences As ComponentOccurrences
oOccurrences = oAsmDoc.ComponentDefinition.Occurrences

' Get the drawing curves that represent the occurrence.
Dim oPartDoc As PartDocument
Dim oObjs As ObjectCollection
Dim oDrawCurves As DrawingCurvesEnumerator
Dim oCurve1 As DrawingCurve
Dim oCurve2 As DrawingCurve
'Dim oEdge1 As Edge
'Dim oEdge2 As Edge
Dim oEdge1 As Face
Dim oEdge2 As Face

' Get the desired occurrence.
Dim oOcc As ComponentOccurrence
For Each oOcc In oOccurrences
' Find the 1st part
' Find the full document name
Dim PartNum As String = Left(oOcc.Name, oOcc.Name.IndexOf(":"))
If PartNum = Part1 Then
FindComponent(PartNum, "G:\Engineering Automation Development")

' Open the part document in the background
oPartDoc = invApp.Documents.Open(InvPartPath, False)

' Get the attribute manager.
Dim attribMgr As AttributeManager
attribMgr = oPartDoc.AttributeManager

' Find all attribute sets named "CCSC".
Dim foundEntities As ObjectCollection
foundEntities = attribMgr.FindObjects("CCSC")

MsgBox("Found " & foundEntities.Count & " entities.")

' Get the required edges of the part
oObjs = oPartDoc.AttributeManager.FindObjects("CCSC", "P" & PartNum, AttName1)

******************----Code crashes on the line below----*******************
oEdge1 = oObjs.Item(1)

' Get the associated drawingcurve
oDrawCurves = oDrawView.DrawingCurves(oEdge1)
oCurve1 = oDrawCurves.Item(1)

oPartDoc.Close()
oPartDoc = Nothing
GC.Collect()
End If

' Find the 2nd part
If PartNum = Part2 Then
FindComponent(PartNum, "G:\Engineering Automation Development")

' Open the part document in the background
oPartDoc = invApp.Documents.Open(InvPartPath, False)

' Get the required edges of the part
oObjs = oPartDoc.AttributeManager.FindObjects("CCSC", "P" & PartNum, AttName2)
oEdge2 = oObjs.Item(1)

' Get the associated drawingcurve
oDrawCurves = oDrawView.DrawingCurves(oEdge2)
oCurve2 = oDrawCurves.Item(1)

oPartDoc.Close()
oPartDoc = Nothing
GC.Collect()
End If
Next

If oCurve1 Is Nothing Then
MsgBox("Curve 1 was not set")
Exit Sub
End If

Dim oTG As TransientGeometry
oTG = invApp.TransientGeometry

' Create the dimensions.
Dim oGeneralDims As GeneralDimensions
oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions
Dim oDim As GeneralDimension
oDim = oGeneralDims.AddLinear(oTG.CreatePoint2d(0, 0), oSheet.CreateGeometryIntent(oCurve1), oSheet.CreateGeometryIntent(oCurve2), DimensionTypeEnum.kVerticalDimensionType)

End Sub
{code} Edited by: Herrwolf1 on Feb 8, 2010 12:52 PM
11 REPLIES 11
Message 2 of 12
alewer
in reply to: herrwolf1

Try replacing "oEdge1 = oObjs.Item(1)" with "oEdge1 = oObjs.Item(0)"
Message 3 of 12
rusmwb
in reply to: herrwolf1

I realize this is an old post, but it seems to get a lot of views.

 

You need to create EdgeProxies since you are working in an assembly context.

 

After this line, oEdge1 = oObjs.Item(1)

Add

Dim oEdgeProx1 As Inventor.EdgeProxy
        oCompOcc.CreateGeometryProxy(oEdge1, oEdgeProx1)

 Then change the line that reads; oDrawCurves = oDrawView.DrawingCurves(oEdge1)

To

oDrawCurves = oView.DrawingCurves(oEdgeProx1)

 Then do the same for Edge2.

Message 4 of 12
HvHelden
in reply to: rusmwb

Good day Rusmwb,

 

Since I was searching for creating dimensions with ilogic or VBA, i come to this thread. I come with the same problem as Herrwolff came in the past, but when I see your Reply for using Proxies because we work in the Assembly context, I search in VBA-editor for Proxy, and now i am thinking: is a Drawing/DWG an Assembly-context too?

I would like to place dimensions on over 2 parts (occurrences of an Assembly) in Inventor DWG. Working with Attributes and VBA.

 

Hope you can explain a little bit.

 

Best regards,

 

HvanHelden

 

Message 5 of 12
rusmwb
in reply to: HvHelden

Yes you need to work with proxies in the drawing document too as well as drawing curves.

Here is a vb.net function that I have used to add general dimensions between two different parts that have a specific attribute.

 

 Public Function AddGenDim(ByRef oSheet As Inventor.Sheet, _
                             ByRef oView As Inventor.DrawingView, _
                             ByRef oAssyDoc As Inventor.AssemblyDocument, _
                             ByRef Comp1occNum As Integer, _
                             ByRef Edge1Name As String, _
                             ByRef Comp2occNum As Integer, _
                             ByRef Edge2Name As String, _
                             ByRef DimOrient As String, _
                             ByRef DimLoc As String) As Inventor.GeneralDimension

        'Get the part occurrence where the named edges are
        Dim oComp1occ As Inventor.ComponentOccurrence
        oComp1occ = oAssyDoc.ComponentDefinition.Occurrences.Item(Comp1occNum)

        Dim oPartDoc1 As Inventor.PartDocument
        oPartDoc1 = oComp1occ.Definition.Document

        Dim oTG As TransientGeometry
        oTG = _invApp.TransientGeometry

        'open part in background
        _invApp.Documents.Open(oPartDoc1.FullFileName, False)

        'Get the edges that have the attribute name
        Dim oObjs As ObjectCollection
        oObjs = oPartDoc1.AttributeManager.FindObjects("MyAttName", "MyAttName", Edge1Name)

        'MsgBox("found " & oObjs.Count)

        Dim oEdge1 As Inventor.Edge
        oEdge1 = oObjs.Item(1)

        Dim oEdgeProx1 As Inventor.EdgeProxy = Nothing
        oComp1occ.CreateGeometryProxy(oEdge1, oEdgeProx1)

        Dim oDrawCurves As DrawingCurvesEnumerator
        'oDrawCurves = oView.DrawingCurves(oEdge1)
        oDrawCurves = oView.DrawingCurves(oEdgeProx1)

        Dim oDrawCurve1 As DrawingCurve
        oDrawCurve1 = oDrawCurves.Item(1)

        Dim oPartDoc2 As Inventor.PartDocument
        Dim oComp2occ As Inventor.ComponentOccurrence

        If Comp1occNum <> Comp2occNum Then
            oComp2occ = oAssyDoc.ComponentDefinition.Occurrences.Item(Comp2occNum)
            oPartDoc2 = oComp2occ.Definition.Document
            If oPartDoc2.FullFileName <> oPartDoc1.FullFileName Then
                _invApp.Documents.Open(oPartDoc2.FullFileName, False)
            End If
        Else
            oComp2occ = oComp1occ
            oPartDoc2 = oPartDoc1
        End If

        Dim oEdge2 As Edge
        oObjs = oPartDoc2.AttributeManager.FindObjects("MyAttName", "MyAttName", Edge2Name)
        oEdge2 = oObjs.Item(1)

        'MsgBox("found " & oObjs.Count)

        Dim oEdgeProx2 As Inventor.EdgeProxy = Nothing
        oComp2occ.CreateGeometryProxy(oEdge2, oEdgeProx2)

        oDrawCurves = oView.DrawingCurves(oEdgeProx2)
        Dim oDrawCurve2 As DrawingCurve
        oDrawCurve2 = oDrawCurves.Item(1)

        Dim oDimType As DimensionTypeEnum
        If DimOrient = "Hor" Then
            oDimType = DimensionTypeEnum.kHorizontalDimensionType
        ElseIf DimOrient = "Ver" Then
            oDimType = DimensionTypeEnum.kVerticalDimensionType
        Else
            oDimType = DimensionTypeEnum.kAlignedDimensionType
        End If

        Dim MinY(3) As Double
        MinY(0) = oDrawCurve1.StartPoint.Y
        MinY(1) = oDrawCurve1.EndPoint.Y
        MinY(2) = oDrawCurve2.StartPoint.Y
        MinY(3) = oDrawCurve2.EndPoint.Y

        Dim MinX(3) As Double
        MinX(0) = oDrawCurve1.StartPoint.X
        MinX(1) = oDrawCurve1.EndPoint.X
        MinX(2) = oDrawCurve2.StartPoint.X
        MinX(3) = oDrawCurve2.EndPoint.X

        Dim oPlaceDimX As Double = 0
        Dim oPlaceDimY As Double = 0

        'Horizontal and Below
        If DimOrient = "Hor" Then
            oPlaceDimX = (oDrawCurve1.StartPoint.X + oDrawCurve2.StartPoint.X) / 2
            If DimLoc = "Below" Then
                oPlaceDimY = MinY.Min - 0.5
            ElseIf DimLoc = "Above" Then
                oPlaceDimY = MinY.Min + 0.5
            End If
        ElseIf DimOrient = "Ver" Then
            oPlaceDimY = (oDrawCurve1.StartPoint.Y + oDrawCurve2.StartPoint.Y) / 2
            If DimLoc = "Left" Then
                oPlaceDimX = MinX.Min - 0.5
            ElseIf DimLoc = "Right" Then
                oPlaceDimX = MinX.Min + 0.5
            End If
        End If

        Dim oPT As Point2d
        oPT = oTG.CreatePoint2d(oPlaceDimX, oPlaceDimY)

        'create dimensions
        Dim oGeneralDims As GeneralDimensions
        oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions

        Dim oDim As GeneralDimension
        oDim = oGeneralDims.AddLinear(
            oPT,
            oSheet.CreateGeometryIntent(oDrawCurve1),
            oSheet.CreateGeometryIntent(oDrawCurve2),
            oDimType)

        oPartDoc1.Close(False)
        If Comp2occNum <> Comp1occNum Then
            oPartDoc2.Close(False)
        End If

        Return oDim

    End Function

 

Here is the call to that function that you would make in the sub routine

 

Dim oWidthDim As GeneralDimension
 oWidthDim = AddGenDim(oSheet, oFaceView, oAssyDoc, 1, "RightEdge", 1, "LeftEdge", "Hor", "Below")
Message 6 of 12
HvHelden
in reply to: rusmwb

Hello rusmwb!
 
 
 
Sow, that was an quick reply, thanks a lot!
 
And I think your code is helping me too, but afther reading and learning a lot about iLogic, VBA and COM last 2 months; I am not familiar with the function you place. 
 
 
The attatchment 'RuleWithMainSub' shows how I place the function in a Module in my VBA.
 
The rule gives red lines, so I know that gives errors.
 
 
 
Then I place your code into the first Module, like attatchment 'Rule', where I declare all the parameters.
 
 
 
That gives error on the Proxy only (See annex: 'Rule_ErrorOnProxy'), so I think, is it possible that my VBA or iLogic doesn´t have "CreateGeometryProxy"? When I search for it in the VBA-editor, it has one, so i don't think so.
 
 
 
 
Or can you explain a bit where I have to post that code?
 
 
 
 
Hopefully you can help me a bit,
Thanks in advance for your trouble!,
 
 
H
vanHelden
 
 
 
PS: You speak about VB.Net, is it correct i work with that for now? How can I ensure that? I open VBA from Inventor under Tools>Options>VBA Editor.
 
Message 7 of 12
rusmwb
in reply to: HvHelden

The code I provided was from a vb.net application. VBA is a little bit different which is why you are getting some syntax errors. Do a little research on the differences between vb.net and vba as well as proxies and you should be able to resolve it.

Message 8 of 12
HvHelden
in reply to: rusmwb

Hello all!

 

That VBA and iLogic works nice, and rusmwb code and reply works really nice!

But i have an problem with 1 kind of dimension to place. In this message-attatchment you can find an package with drawing, assembly and parts like i have to dimension. In the JPG's you can see the settings from the attributes. The flat sides of the shaft must be dimensioned, but it doesn´t work.

I make an iLogic rule for creating dimension on the block, wich wil work fine! (Dimension from 1 part to another will work to! But in this assembly I haven't built in it.)

Copy that for dimensioning the shaft-flats, and it doesn't work; an H-result-Exception-error come up.

Then I add an color-changer for the searched shaft-edges (drawingcurves) to see or iLogic see the 'right' edges; and yes; exact the edges needed for creation the dimension are changed their color!! (press UNDO 2times for original settings.)

 

So I am looking for what I am doing wrong.

Could someone help me out of this?

The bug is specially on the line:  "Set oDim = oGeneralDims.AddLinear(oPlaceDim1, oSheet.CreateGeometryIntent(oDrawCurve1), oSheet.CreateGeometryIntent(oDrawCurve2), oDimType)", and when I use Parameter Info (CTRL+SHIFT+D); I see the IntentTwo is not followed with 'as Geometry Intent', like IntentOne, and in square brackets. Why?

 

The commented lines in the rule maybe could explain you enouch for what I am doing in the rule; but for short: in the first section you see an declaration of the file, and dimension-specific parameters (Attributes+position) are given ONLY in that second section; (the only section wich cannot be collapsed).

 

In VBA editor you see the wrong rule translated under Module1 from the drawing file; maybe you could find the bug faster trough that workspace.

 

The rule is mostly from rusmwb, thanks! But all others on internet thanks for all the stuff.

 

Hopefully someone could help me; thanks in advance!!

 

Greetz, and have a nice day!

HvanHelden

 

VBA-code:

 

 

Sub ShaftFlat()

'[============= Algemene declaratie =============

Dim invApp As Application
Set invApp = ThisApplication

' Get the Active Drawing document
Dim oDrawDoc As Inventor.DrawingDocument
Set oDrawDoc = invApp.ActiveDocument

' Get the active sheet
Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet

' Get the just DrawingView
Dim oView As DrawingView
Set oView = oSheet.DrawingViews.Item(1)
'Debug.Print oView.Name

' Get reference to document from wich the drawingview is made
Dim oAssyDoc As Inventor.AssemblyDocument
Set oAssyDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

' Get all Components
Dim oOccurrences As ComponentOccurrences
Set oOccurrences = oAssyDoc.ComponentDefinition.Occurrences
']

''' BETWEEN THIS LINE AND NEXT GREEN LINE, YOU COULD GIVE THE INFORMATION FOR PLACE THE DIMENSION YOU WANT TO CREATE!!!
' Set number of Occurrence1 in Assembly-tree
Dim Comp1occNum As Integer
    Comp1occNum = 2
    
' Set number of Occurrence2 in Assembly-tree
Dim Comp2occNum As Integer
    Comp2occNum = 2

'Gives the Attribute-information for searching the right

' Set attribute-1-style; for select Face or Edge-proxies and geometries
Dim AttStyle1 As String
    AttStyle1 = "Face"  'or: "Edge"

' Set attribute-1-value
Dim AttSet1 As String
    AttSet1 = "ShaftFlat1"

' Set attribute-1-value
Dim AttName1 As String
    AttName1 = "ShaftFlat1"
    
' Set attribute-1-value
Dim AttValue1 As String
    AttValue1 = "1"
        
' Set attribute-2-style; for select Face or Edge-proxies and geometries
Dim AttStyle2 As String
    AttStyle2 = "Face"  'or: "Edge"

' Set attribute-2-value
Dim AttSet2 As String
    AttSet2 = "ShaftFlat2"

' Set attribute-2-value
Dim AttName2 As String
    AttName2 = "ShaftFlat2"
    
' Set attribute-2-value
Dim AttValue2 As String
    AttValue2 = "2"

'Set X- and Y-position of dimenion-line and text:
Dim DimPlaceX As Double                                                                                                         '=4 omdat het schaal 1:2 is, =10 omdat hij in [cm] ipv. [mm] werkt
    DimPlaceX = (oView.Left + oView.Width / 2)

Dim DimPlaceY As Double
    DimPlaceY = (oView.Top - (oView.Height / 2))
    
    ''' END OF EDITING ZONE FOR CREATING DIMENSIONS YOU WANT TO CREATE !!!


'''' Ready's code for create aligned dimension
'''Dim DimOrient As String
'''Dim DimLoc As String

'[======================= Take edges of part1 ==================================
'-----------------------                     ----------------------------------

    'Get the occurrence-PARTFILE where the named attributes are
    Dim oComp1occ As Inventor.ComponentOccurrence
    Set oComp1occ = oAssyDoc.ComponentDefinition.Occurrences.Item(Comp1occNum)

    'Set reference to that file
    Dim oPartDoc1 As Inventor.PartDocument
    Set oPartDoc1 = oComp1occ.Definition.Document

    'Open part in background
    Dim oPartDoc As Inventor.Document
    Set oPartDoc = invApp.Documents.Open(oPartDoc1.FullFileName, False)

    'Get the objects that have the attribute-name
    Dim oObjs As ObjectCollection
    Set oObjs = oPartDoc1.AttributeManager.FindObjects(AttSet1, AttName1, AttValue1)
'MsgBox ("Found Attribute-objects in AttributeSet1: " & oObjs.Count)

    'Declare oDrawCurves to place a curve in
    Dim oDrawCurves As DrawingCurvesEnumerator
    

'Search right Attribute-1-style, for create right proxies.
'When attribute-1 lies on a 'face':
If AttStyle1 = "Face" Then
    'Set Face where Attribute-1 lies
    Dim oFace1 As Inventor.Face
    Set oFace1 = oObjs.Item(1)

    'Make Face-GeometryProxy for geometry translation in from Part to DWG or Assembly.
    Dim oFaceProx1 As Inventor.FaceProxy
        oComp1occ.CreateGeometryProxy oFace1, oFaceProx1
    
    'Take DrawingView-Drawcurves from the Face-GeometryProxy
        Set oDrawCurves = oView.DrawingCurves(oFaceProx1)
Debug.Print ("Found Faces in proxy-1: " & oDrawCurves.Count)
'MsgBox ("Found Faces in proxy-1: " & oDrawCurves.Count)


'When attribute lies on a 'edge':
ElseIf AttStyle1 = "Edge" Then
    'Set Edge where Attribute-1 lies
    Dim oEdge1 As Inventor.Edge
    Set oEdge1 = oObjs.Item(1)

    'Make Edge-GeometryProxy for geometry translation in from Part to DWG or Assembly.
    Dim oEdgeProx1 As Inventor.EdgeProxy
        oComp1occ.CreateGeometryProxy oEdge1, oEdgeProx1
    
    'Take DrawingView-Drawcurves from the Edge-GeometryProxy
        Set oDrawCurves = oView.DrawingCurves(oEdgeProx1)
'MsgBox ("Found Edges in proxy-1: " & oDrawCurves.Count)
End If

    'Take the first item (I think in this case there are no more than one item!)
    Dim oDrawCurve1 As DrawingCurve
    Set oDrawCurve1 = oDrawCurves.Item(1)
']
    
'[======================= Take edges of part2 ==================================
'-----------------------                     ----------------------------------

    'Get the occurrence-PARTFILE where the named attributes are
    Dim oPartDoc2 As Inventor.PartDocument
    Dim oComp2occ As Inventor.ComponentOccurrence

    'When occ.numbers not the same, set occurrence-PARTFILE-2
    If Comp1occNum <> Comp2occNum Then
        Set oComp2occ = oAssyDoc.ComponentDefinition.Occurrences.Item(Comp2occNum)
        Set oPartDoc2 = oComp2occ.Definition.Document
        'When PARTFILE-2 is not the same as PARTFILE-1, then open PARTFILE-2 in the background
        If oPartDoc2.FullFileName <> oPartDoc1.FullFileName Then
        Set oPartDoc = invApp.Documents.Open(oPartDoc2.FullFileName, False)
        End If
        
    'When occ.numbers the same, set occurrence-PARTFILE-2 = occurrence-PARTFILE-1
    Else
        Set oComp2occ = oComp1occ
        Set oPartDoc2 = oPartDoc1
    End If

    'Get the objects that have the attribute-name
    Dim oObjs2 As ObjectCollection
    Set oObjs2 = oPartDoc2.AttributeManager.FindObjects(AttSet2, AttName2, AttValue2)
'MsgBox ("Found Attribute-objects in AttributeSet2: " & oObjs2.Count)

'Search right Attribute-2-style, for create right proxies.
'When attribute-2 lies on a 'face':
If AttStyle2 = "Face" Then
    'Set Face where Attribute-2 lies
    Dim oFace2 As Inventor.Face
    Set oFace2 = oObjs2.Item(1)

    'Make Face-GeometryProxy for geometry translation in from Part to DWG or Assembly.
    Dim oFaceProx2 As Inventor.FaceProxy
        oComp2occ.CreateGeometryProxy oFace2, oFaceProx2
    
    'Take DrawingView-Drawcurves from the Face-GeometryProxy
        Set oDrawCurves = oView.DrawingCurves(oFaceProx2)
Debug.Print ("Found Faces in proxy-2: " & oDrawCurves.Count)
'MsgBox ("Found Faces in proxy-2: " & oDrawCurves.Count)

'When attribute-2 lies on a 'edge':
ElseIf AttStyle2 = "Edge" Then
    'Set Edge where Attribute-2 lies
    Dim oEdge2 As Inventor.Edge
    Set oEdge2 = oObjs2.Item(1)

    'Make Edge-GeometryProxy for geometry translation in from Part to DWG or Assembly.
    Dim oEdgeProx2 As Inventor.EdgeProxy
        oComp2occ.CreateGeometryProxy oEdge2, oEdgeProx2
    
    'Take DrawingView-Drawcurves from the Edge-GeometryProxy
        Set oDrawCurves = oView.DrawingCurves(oEdgeProx2)
'MsgBox ("Found Edges in proxy-2: " & oDrawCurves.Count)
End If

    'Take the first item (I think in this case there are no more than one item!)

    Dim oDrawCurve2 As DrawingCurve
    Set oDrawCurve2 = oDrawCurves.Item(1)
']
        
'[================ Make TransientGeometry and place dimension ================
    Dim oDimType As DimensionTypeEnum
    If DimOrient = "Hor" Then
        oDimType = DimensionTypeEnum.kHorizontalDimensionType '60162
    ElseIf DimOrient = "Ver" Then
        oDimType = DimensionTypeEnum.kVerticalDimensionType '60163
    Else
        oDimType = DimensionTypeEnum.kAlignedDimensionType '60161
    End If

    ' Ready's code for TransientGeometry, needed for working with X,Y coordinates in Sheet
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry
        
    Dim oPlaceDim1 As Point2d
    Set oPlaceDim1 = oTG.CreatePoint2d(DimPlaceX, DimPlaceY)

        'Create dimensions
    Dim oGeneralDims As GeneralDimensions
    Set oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions
    
Debug.Print ("Existing dimensions: " & oGeneralDims.Count)

    Dim oDim As GeneralDimension
    Set oDim = oGeneralDims.AddLinear(oPlaceDim1, oSheet.CreateGeometryIntent(oDrawCurve1), oSheet.CreateGeometryIntent(oDrawCurve2), oDimType)

    Dim oDim1Att As AttributeSet
    Set oDim1Att = oDim.AttributeSets.Add("ilogic_Created")
        
        oPartDoc1.Close (False)
        
    If Comp2occNum <> Comp1occNum Then
        oPartDoc2.Close (False)
    End If
']
End Sub

 

 

Message 9 of 12
phewphonics
in reply to: herrwolf1

I found your post extremely helpful. Thankyou.

 

I have also been trying to get a method of autodimensioing which uses workplanes in a single skeletal part (which drives my assembly) instead of faces or edges, but seem to be having little success referencing the workplane proxies with the drawing curves.

 

I tried to update the following coding used in the following rule to point to a part within the assembly shown on the drawing & use 

2 workplane attributes Ihad set on workplanes in the part.

 

..................................................................................................

'---INITIAL SETUP---------

'References this document
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDoc.Document

'References this drawing sheet
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet

'References this drawing view
Dim oView As DrawingView
oView = ActiveSheet.View("VIEW").View

'References this drawing view model
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ActiveSheet.View("VIEW").ModelDocument

'Readys code for Creation of reference points for dimension placement
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

'Readys code for creation of general dimensions
Dim oGeneralDims As GeneralDimensions
oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions


'---DIMENSION PREP------------

'finds edges with a particular attributes then taks the first instance
Dim aoEdge4 as face
oObjs = oAssyDoc.AttributeManager.FindObjects("ATTRIBUTE SET", "ATTRIBUTE", "VARIABLE")
aoEdge4 = oObjs.Item(1)

'finds edges with a particular attributes then taks the first instance
Dim aoEdge3 as face
oObjs = oAssyDoc.AttributeManager.FindObjects("ATTRIBUTE SET", "ATTRIBUTE", "VARIABLE'')
aoEdge3 = oObjs.Item(1)

'Finds the drawing edge that represents the one with the attribute
Dim aoDrawCurves4 As DrawingCurve
oDrawViewCurves = oView.DrawingCurves(aoEdge4)
aoDrawCurves4 = oDrawViewCurves.Item(1)
'
'Finds the drawing edge that represents the one with the attribute
Dim aoDrawCurves3 As DrawingCurve
oDrawViewCurves = oView.DrawingCurves(aoEdge3)
aoDrawCurves3 = oDrawViewCurves.Item(1)
'

Dim oPt2 As Point2d
oPt2 = oTG.CreatePoint2d(oView.Left + (oView.Width/2 ),oView.Top - (oView.Height) - 1)

'
'---CREATING DIMENSIONS------------
'
Dim oDim2 As GeneralDimension
oDim2 = oGeneralDims.AddLinear(oPt2, oSheet.CreateGeometryIntent(aoDrawCurves3), oSheet.CreateGeometryIntent(aoDrawCurves4))

'oDim2.text.FormattedText = oDim2.text.FormattedText  & " OVERALL INTERNAL LENGTH "

Dim oDim2Att As AttributeSet
ODim2Att = oDim2.AttributeSets.Add("ilogic_Created")

 

Any assiatnce would be truly appreciated.

 

Regards

 

 

Wayne

Message 10 of 12
rusmwb
in reply to: phewphonics

Hi Wayne,

I haven't gotten too deep in this but it seems that the these lines of code would find the same object (face) rather than two different ones.

 

'finds edges with a particular attributes then taks the first instance
Dim aoEdge4 as face
oObjs = oAssyDoc.AttributeManager.FindObjects("ATTRIBUTE SET", "ATTRIBUTE", "VARIABLE")
aoEdge4 = oObjs.Item(1)

 

'finds edges with a particular attributes then taks the first instance
Dim aoEdge3 as face
oObjs = oAssyDoc.AttributeManager.FindObjects("ATTRIBUTE SET", "ATTRIBUTE", "VARIABLE'')
aoEdge3 = oObjs.Item(1)

Message 11 of 12
phewphonics
in reply to: rusmwb

Yes. But It does seem to work - for example like this. 

Were you referring to this reference : "oObjs.Item(1)" which is the same for both edges?

 


Dim aoEdge4 as face
oObjs = oAssyDoc.AttributeManager.FindObjects("SIDEA", "A_DIM", "1")
aoEdge4 = oObjs.Item(1)

 


Dim aoEdge3 as face
oObjs = oAssyDoc.AttributeManager.FindObjects("SIDEB", "B_DIM", "1'')
aoEdge3 = oObjs.Item(1)

 

I have also since discovered - that I cannot use WorkPlaneProxies for calling these auto dimensions on a drawing

because I can only attach to Faces, Sketches, Bodies etc, so I am using a surfaceface (instead of a plane) which I can turn off in the drawing view without losing my dimension.

 

Thanks very much for your response. Much appreciated.

 

 

Wayne

 

Message 12 of 12
phewphonics
in reply to: rusmwb

'---INITIAL SETUP---------

 

'References this document

Dim oDrawDoc As DrawingDocument

oDrawDoc = ThisDoc.Document

 

'References this drawing sheet

Dim oSheet As Sheet

oSheet = oDrawDoc.ActiveSheet

 

'References this drawing view

Dim oView As DrawingView

oView = ActiveSheet.View("VIEW4").View

 

'References this drawing view model

Dim oAssyDoc As AssemblyDocument

oAssyDoc = ActiveSheet.View("VIEW4").ModelDocument

 

'Reference the first Sub-part in my assembly shown in the Drawing View (1) or (2) or so on

 Dim occ As ComponentOccurrence

occ = oAssyDoc.ComponentDefinition.Occurrences.Item(1)

 

'I only used this to check I was referencing the right Sub-part in my assembly shown in the drawing view

If occ.Name = "YourSubPartName:1" Then

MessageBox.Show(occ.Name, "Title")

'You can also put your auto dim rule here if you only want the AutoDims run if this sub-part exists

End If

 

 

'Readys code for Creation of reference points for dimension placement

Dim oTG As TransientGeometry

oTG = ThisApplication.TransientGeometry

 

'Readys code for creation of general dimensions

Dim oGeneralDims As GeneralDimensions

oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions

 

 

 

'---DIMENSION PREP------------

 

'finds edges with a particular attributes then taks the first instance

Dim aoEdge4 As Face

oObjs = occ.Definition.Document.AttributeManager.FindObjects("SURFACE1", "DIMP1", "1")

occ.CreateGeometryProxy(oObjs.Item(1), aoEdge4)

 

 

'finds edges with a particular attributes then taks the first instance

Dim aoEdge3 As Face

oObjs = occ.Definition.Document.AttributeManager.FindObjects("SURFACE2", "DIMP2", "1")

occ.CreateGeometryProxy(oObjs.Item(1), aoEdge3)

 

 

'

'

'Finds the drawing edge that represents the one with the attribute

Dim aoDrawCurves1 As DrawingCurve

oDrawViewCurves = oView.DrawingCurves(aoEdge4)

aoDrawCurves4 = oDrawViewCurves.Item(1)

 

 

'Finds the drawing edge that represents the one with the attribute

Dim aoDrawCurves2 As DrawingCurve

oDrawViewCurves = oView.DrawingCurves(aoEdge3)

aoDrawCurves3 = oDrawViewCurves.Item(1)

 

 

 

Dim oPt2 As Point2d

oPt2 = oTG.CreatePoint2d(oView.Left + (oView.Width/2 ),oView.Top - (oView.Height) - 1)

 

'

'---CREATING DIMENSIONS------------

'

Dim oDim2 As GeneralDimension

oDim2 = oGeneralDims.AddLinear(oPt2, oSheet.CreateGeometryIntent(aoDrawCurves3), oSheet.CreateGeometryIntent(aoDrawCurves4))

 

'oDim2.text.FormattedText = oDim2.text.FormattedText  & " OVERALL INTERNAL LENGTH "

 

Dim oDim2Att As AttributeSet

ODim2Att = oDim2.AttributeSets.Add("ilogic_Created")

'

'

‘DELETE AUTO DIMENSION - USE THIS IN A SEPARATE RULE TO REMOVE Any of the above AutoDimensions

 

Dim oDoc as DrawingDocument

oDoc = ThisApplication.ActiveDocument

Dim oSheet As Inventor.Sheet

oSheet = oDoc.ActiveSheet

 

Dim oDim as DrawingDimension

For Each oDim in oSheet.DrawingDimensions

 

If oDim.AttributeSets.Nameisused("ilogic_Created") = True Then

oDim.Delete

 

End If

 

Next

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report