Sketched symbol with custom property

Sketched symbol with custom property

snichols
Advocate Advocate
816 Views
3 Replies
Message 1 of 4

Sketched symbol with custom property

snichols
Advocate
Advocate

I am trying to create a sketched symbol on the fly that has custom properties in it. I am also creating the custom properties on the fly. I need to get the actual expression for the property into the sketched symbol not just a value. I need this so that I can export the drawing as an autocad .dwg that has attributes in it. Anyone have any ideas? Thanks for your tme.

0 Likes
817 Views
3 Replies
Replies (3)
Message 2 of 4

snichols
Advocate
Advocate

Here is the code I have, any help would be appreciated even if its only to tell me it can't be done. Inventor 2009 SP2

 

Public Sub PartListLine() 

' Set a reference to the drawing document.  

' This assumes a drawing document is active.     

Dim oDrawDoc As DrawingDocument     

Set oDrawDoc = ThisApplication.ActiveDocument

       

' Set the user defined (custom) property set     

Dim CustomPropSets As PropertySets     

Set CustomPropSets = oDrawDoc.PropertySets

Dim CustomPropSet As PropertySet     

Set CustomPropSet = CustomPropSets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")

 

Dim sName As String      Dim sValue As String

sName = "PN"      sValue = "123456"

 

Call CustomPropSet.Add(sValue, sName)

 

'Update the document    

oDrawDoc.Update

 

' Create the new sketched symbol definition.    

Dim oSketchedSymbolDef As SketchedSymbolDefinition    

Set oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Add("Part List")

 

' Open the sketched symbol definition's sketch for edit. This is done by calling the Edit    

 ' method of the SketchedSymbolDefinition to obtain a DrawingSketch. This actually creates    

 ' a copy of the sketched symbol definition's and opens it for edit.    

Dim oSketch As DrawingSketch    

Call oSketchedSymbolDef.Edit(oSketch)

 

Dim oTG As TransientGeometry    

Set oTG = ThisApplication.TransientGeometry

   

' Use the functionality of the sketch to add sketched symbol graphics.    

Dim oRectangleLines As SketchEntitiesEnumerator    

Set oRectangleLines = oSketch.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(0, 0), _

                                                                                oTG.CreatePoint2d(7.375 * 2.54, 0.1875 * 2.54))       

Dim oSketchLine1 As SketchLine    

Set oSketchLine1 = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0.375 * 2.54, 0), _

                                                                               oTG.CreatePoint2d(0.375 * 2.54, 0.1875 * 2.54))       

Dim oSketchLine2 As SketchLine    

Set oSketchLine2 = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0.75 * 2.54, 0), _

                                                                               oTG.CreatePoint2d(0.75 * 2.54, 0.1875 * 2.54))       

Dim oSketchLine3 As SketchLine    

Set oSketchLine3 = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(1.75 * 2.54, 0), _

                                                                               oTG.CreatePoint2d(1.75 * 2.54, 0.1875 * 2.54))       

Dim oSketchLine4 As SketchLine    

Set oSketchLine4 = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(4.75 * 2.54, 0), _

                                                                                oTG.CreatePoint2d(4.75 * 2.54, 0.1875 * 2.54))       

Dim oSketchLine5 As SketchLine    

Set oSketchLine5 = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(5.625 * 2.54, 0), _

                                                                               oTG.CreatePoint2d(5.625 * 2.54, 0.1875 * 2.54))       

 Dim oSketchLine6 As SketchLine    

Set oSketchLine6 = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(6.5 * 2.54, 0), _

                                                                                 oTG.CreatePoint2d(6.5 * 2.54, 0.1875 * 2.54))         

Dim oPoint As SketchPoint     

Set oPoint = oSketch.SketchPoints.Add(oTG.CreatePoint2d(7.375 * 2.54, 0.1875 * 2.54))

          

' Make the work point of the sketch the insertion point     

oPoint.InsertionPoint = True

 

 ''''THIS IS WHERE i WANT IT TO INSERT THE CUSTOM DRAWING PROPERTY <PN> INTO THE TEXT BOX

''''ALL I CAN GET IS THE VALUE        

 'Add custom properties to the sketch symbol.   

Dim oTextBox As TextBox    

Set oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d((0.375 * 2.54) / 2, (0.1875 * 2.54) / 2), _                                                      CustomPropSets.Item("User Defined Properties").Item("PN").Expression)

 

oTextBox.VerticalJustification = kAlignTextMiddle    

oTextBox.HorizontalJustification = kAlignTextCenter

 

Call oSketchedSymbolDef.ExitEdit(True)

 

'Set a reference to the active sheet.    

Dim oDrgSheet As Sheet    

Set oDrgSheet = oDrawDoc.ActiveSheet

 

' Set a reference to the sheet's border    

Dim oBorder As Border     Set oBorder = oDrgSheet.Border

Dim oPlacementPoint As Point2d

 

   If Not oBorder Is Nothing Then        

     ' A border exists. The placement point        

     ' is the top-right corner of the border.        

Set oPlacementPoint = oBorder.RangeBox.MaxPoint     Else        

    ' There is no border. The placement point        

    ' is the top-right corner of the sheet.        

Set oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oDrawDoc.Width, oDrawDoc.height)    

  End If

 

' Add an instance of the sketched symbol definition to the sheet.    

' Rotate the instance by 0 degrees and scale by 1 when adding.    

' The symbol will be inserted at the upper right corner of the sheet.    

 Dim oSketchedSymbol As SketchedSymbol    

Set oSketchedSymbol = oDrgSheet.SketchedSymbols.Add(oSketchedSymbolDef, oPlacementPoint, (0), 1)

 

End Sub

0 Likes
Message 3 of 4

snichols
Advocate
Advocate

The code below almost gets me what I need. If I create a sketched symbol and manually insert the custom property text

when I save it as an AutoCad.dwg it has attributes. The below does not have attributes when saved the same way. Is there anyone that can explain the difference between manually inserted property text and programatically inserted property text. If you want to test this just create a custom property named PN1.

Thanks,

 

 

Sub PartList()

    Dim oDrawDoc As DrawingDocument 

   Set oDrawDoc = ThisApplication.ActiveDocument     

   Dim CustomPropSets As PropertySets     

   Set CustomPropSets = oDrawDoc.PropertySets     

   Dim CustomPropSet As PropertySet     

   Set CustomPropSet = CustomPropSets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")     

   Dim oDrgSheet As Sheet     

   Set oDrgSheet = oDrawDoc.ActiveSheet     

   Dim oBorder As Border      Set oBorder = oDrgSheet.Border

 

    ' Create the new sketched symbol definition.    

   Dim oSketchedSymbolDef As SketchedSymbolDefinition    

   Set oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Add("Part List")

 

    ' Open the sketched symbol definition's sketch for edit. This is done by calling the Edit    

    ' method of the SketchedSymbolDefinition to obtain a DrawingSketch. This actually creates    

    ' a copy of the sketched symbol definition and opens it for edit.    

   Dim oSketch As DrawingSketch    

   Call oSketchedSymbolDef.Edit(oSketch)

   Dim oTG As TransientGeometry    

   Set oTG = ThisApplication.TransientGeometry

 

    ' Use the functionality of the sketch to add sketched symbol graphics.    

   Dim oRectangleLines As SketchEntitiesEnumerator    

   Set oRectangleLines = oSketch.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(0, 0), _

                                                                                    oTG.CreatePoint2d(7.375 * 2.54, 0.1875 * 2.54))

    Dim oSketchLine1 As SketchLine    

   Set oSketchLine1 = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0.375 * 2.54, 0), _

                                                                                   oTG.CreatePoint2d(0.375 * 2.54, 0.1875 * 2.54))

     Dim oSketchLine2 As SketchLine    

   Set oSketchLine2 = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0.75 * 2.54, 0), _

                                                                                  oTG.CreatePoint2d(0.75 * 2.54, 0.1875 * 2.54))

     Dim oSketchLine3 As SketchLine    

   Set oSketchLine3 = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(1.75 * 2.54, 0), _

                                                                                  oTG.CreatePoint2d(1.75 * 2.54, 0.1875 * 2.54))

     Dim oSketchLine4 As SketchLine    

   Set oSketchLine4 = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(4.75 * 2.54, 0), _

                                                                                  oTG.CreatePoint2d(4.75 * 2.54, 0.1875 * 2.54))

     Dim oSketchLine5 As SketchLine    

   Set oSketchLine5 = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(5.625 * 2.54, 0), _

                                                                                 oTG.CreatePoint2d(5.625 * 2.54, 0.1875 * 2.54))

     Dim oSketchLine6 As SketchLine    

   Set oSketchLine6 = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(6.5 * 2.54, 0), _

                                                                                  oTG.CreatePoint2d(6.5 * 2.54, 0.1875 * 2.54))

     Dim oPoint As SketchPoint     

    Set oPoint = oSketch.SketchPoints.Add(oTG.CreatePoint2d(7.375 * 2.54, 0.1875 * 2.54))

 

       ' Make the work point of the sketch the insertion point     

    oPoint.InsertionPoint = True

 

     'Add custom properties to the sketch symbol.

'''''THIS GETS THE CUSTOM PROPERTY INSERTED AS AN EXPRESSION, HOWEVER WHEN I SAVE IT AS AN '''''AUTOCAD.DWG IT HAS NO ATTRIBUTES.    

   Dim sText As String    

   sText = "<Property Document='drawing' PropertySet='CustomPropSet' Property='PN1' FormatID= _

                                                            '{D5CDD505-2E9C-101B-9397-08002B2CF9AE}'></Property>"

 

    Dim oTextBox As TextBox    

   Set oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d((0.375 * 2.54) / 2, (0.1875 * 2.54) / 2), sText)         

   oTextBox.VerticalJustification = kAlignTextMiddle    

   oTextBox.HorizontalJustification = kAlignTextCenter

 

    Call oSketchedSymbolDef.ExitEdit(True)

 

    Dim oPlacementPoint As Point2d

    If Not oBorder Is Nothing Then        

      ' A border exists. The placement point        

      ' is the top-right corner of the border.        

      Set oPlacementPoint = oBorder.RangeBox.MaxPoint    

   Else        

      ' There is no border. The placement point        

     ' is the top-right corner of the sheet.        

     Set oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oDrawDoc.Width, oDrawDoc.height)     

  End If

 

    ' Add an instance of the sketched symbol definition to the sheet.    

   ' Rotate the instance by 0 degrees and scale by 1 when adding.    

   ' The symbol will be inserted at the upper right corner of the sheet.    

   Dim oSketchedSymbol As SketchedSymbol    

   Set oSketchedSymbol = oDrgSheet.SketchedSymbols.Add("Part List", oPlacementPoint, (0), 1)

 

End Sub

0 Likes
Message 4 of 4

Anonymous
Not applicable

hi,

 

you defined the PN1 custom property only inside the sketched symblo's definition, but did not set a value to that property.

 

I thought you could define the custom property before the sketched symbol's definition. then use it in the symbol.

 

add something like this before your sysmbol definition:

 

 ' Get the custom property set.
        Dim customPropSet As PropertySet
        customPropSet = oDrawDoc.PropertySets.Item( _
        "Inventor User Defined Properties")

        ' Create a new text property. 
        Dim textValue As String
        textValue = "Here's some text."
        Call customPropSet.Add(textValue, "PN1")

 

good luck.

 

0 Likes