Visual Basic Macro - adding custom property

Creator
Creator

I have created a macro that will populate the title block fields in a specific border I set up, but I also want it to create the properties in previously used borders.

 

Can I use an IF statement in Visual Basic to determine if the fields exist? A snippet of my program is below. Currently my IF statement is not doing anything. Is there any other check I can perform in order to determine if the property needs to be created?

 

                ' Connect to a running instance of Solid Edge
                objApp = Marshal.GetActiveObject("SolidEdge.Application")
                ' Get a reference to the active document
                objDoc = objApp.ActiveDocument
                ' Get a reference to the document's property sets collection
                objPropertySets = objDoc.Properties
                objProperties = objPropertySets.Item("custom")

                If objProperties.Item("drafter") Is Nothing Then
                    objProperties.Add("drafter", "--")
                Else
                End If

1 REPLY

Re: Visual Basic Macro - adding custom property

Genius
Genius

You will get a better response by posting in the SE Developer Community, but I will attempt to answer your question.

 

Code snip from the Form Load to scroll through the Custom properties looking for a Property named "Drafter".  If it finds it, it populates a form object and sets An IntFlag to 1

 

objPropertySets = objDocument.Properties

objCustomInfo = objPropertySets.Item("Custom")

intFlag = 0

 

If objCustomInfo.Count > 0 Then

   For Each Me.objDrafterProp In objCustomInfo 

   If (objDrafterProp.Name = "Drafter") Then

      intFlag = 1

      objDrafter = objDrafterProp

      cmbDrafter.Text = objDrafter.Value 

   End If

  Next

    objDrafterProp =Nothing

End If

 

Then on the OK button it checks the IntFlag and either creates the custom property or just updates the existing one.

 

If intFlag = 0 Then 'no Drafter property

  Call objCustomInfo.Add("Drafter", cmbDrafter.Text)

ElseIf intFlag = 1 Then 'Updating Drafter

  For Each Me.objDrafterProp In objCustomInfo

            If (objDrafterProp.Name = "Drafter") Then

                     objDrafter = objDrafterProp

                     objDrafter.Value = cmbDrafter.Text

            End If

     Next 

End If

 

Dale Smith
Mitsubishi Electric Power Products, Inc.
ST9 MP5 - Insight