Custom Properties, NEED HELP

 

I have written code to work with part properties (IE Title, Doc No.) and everthing works out just fine... 

With Custom properties I need to check the custom properties for "X".  If it exsist, I want to send it's value to a txtbox and allow the txtbox to read/write "X"'s value..  If "X" does not exist I want to create it and want to create a way to populate it's value from a text box and then allow that txt box to be read/write to the value as well.  I will then use a different function to check the txtbox data before allowing it to be saved as the value. 

current code (does not work correct):

 

Dim

objpropsets As SolidEdgeFramework.PropertySetsDim objprops As SolidEdgeFramework.PropertiesDim objprop As SolidEdgeFramework.PropertyDim objMaterialCost As SolidEdgeFramework.PropertyPrivateSub TestProps()ForEach objprops In objpropsetsIf objprops.Name = "custom"Then

 ' checks to see if Material Cost property already exsist

 

 ForEach objprop In objpropsIf objprop.Name = "Material Cost"Then

objMaterialCost = objprop

 

MatErr = 0

 Me.txtMaterialCost.Text = objMaterialCost.ValueExitFor

 Else

MatErr = 1

 EndIf

 Next

 'add "material cost" property if it does not exsits

 If MatErr = 1 Then

objprops.Add(

objMaterialCost = objprops.Item(

objprops.Save()

 "Material Cost", 0.0)"Material Cost")EndIf

 

 

 

 EndIf 

 

 

 

 

objpropsets = objDoc.Properties

 

 

 

Posted by: Matt Johnson
Post date: 2/19/2008 2:51:55 AM

3 REPLIES

RE: Custom Properties, NEED HELP

 

This is the code I use. It's VB.NET. It add a custom property, ProductCode, and if it does exist, it asks the user.

 

bk = objApp.ActiveDocument

Dim

propCode AsString = ""

Dim propset As SolidEdgeFramework.PropertySets = bk.Properties

Dim props As SolidEdgeFramework.Properties = propset.Item("Custom")

Dim prop As SolidEdgeFramework.Property

Try

prop = props.Item("ProductCode")

propCode = prop.Value

Catch ex As Exception

EnterValidProdCode:

propCode = InputBox("What is the drawing's three digit Product Code?" & vbCrLf & vbCrLf & _

"Like in EDM_PC. nnp, rcp, gen, tld, etc", "Enter Product Code", propCode)

If Len(propCode) = 0 Then

prop = Nothing

props = Nothing

bk = Nothing

objApp = Nothing

End

ElseIf Len(propCode) 3 Then

GoTo EnterValidProdCode

EndIf

Try

propCode = UCase(propCode)

props.Add("ProductCode", propCode)

Catch

'couldn't add custom property

EndTry

EndTry

 

Posted by: Brian Magill
Post date: 5/5/2008 6:02:45 AM

RE: Custom Properties, NEED HELP

 

Dear Matt

 

I have written a code in VB.NET for you

Just copy the code in VB.NET and run it for and active part document  on click event of a command button.

It requires a text box and a command button

 

Public ObjApp As SolidEdgeFramework.Application

 

Public ObjPart As SolidEdgePart.PartDocument

Public ObjPropertySets As  Object

 

Public ObjProperties As  SolidEdgeFileProperties.Properties

 

Public ObjProperty As  Object

Private Sub  Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles

Dim i As Integer

Dim j As Integer

 

ObjPart = ObjApp.ActiveDocument

ObjPropertySets = ObjPart.Properties

Dim IsPropThere As Boolean = False

For i = 1 To ObjPart.Properties.count

ObjPropertySets = ObjPart.Properties.item(i)

  If ObjPropertySets.name = "Custom" Then

    For j = 1 To ObjPropertySets.count

       ObjProperty = ObjPropertySets.item(j)

              If ObjProperty.name = "Material Cost" Then

               IsPropThere = True

               Exit Sub

            End If

     Next j

End If

If IsPropThere = True Then

Exit For

End If

Next i

If IsPropThere = False Then

         For i = 1 To ObjPart.Properties.count

                   ObjPropertySets = ObjPart.Properties.item(i)

                            If ObjPropertySets.name = "Custom" Then

                                  For j = 1 To ObjPropertySets.count

                                      ObjProperty = ObjPropertySets.item(j)

                                           ObjPropertySets.add("Material Cost", Val(TextBox1.Text))

                                                 IsPropThere = True

                                               ObjPart.Save()

                                              Exit Sub

                                 Next j

              End If

Next i

End If

 End Sub

 

 

Posted by: Sandeep Shewale
Post date: 6/12/2008 7:56:19 PM

RE: Custom Properties, NEED HELP

I had similar problem with ST4, or not a problem, a need to be excat. I updated the code above to meet the requirements in ST4 and also set a check if the user is willing to overwrite the previous found value. Change the StringToBeChecked to the one you want to search for.

 

Imports SolidEdgeFramework

Imports System.Runtime.InteropServices

Imports System.Windows.Forms

 

Public Class Form1

 

Private Sub Button1_Click(ByVal sender As System.Object, e As System.EventArgs) Handles Button1.Click

Dim objApplication As SolidEdgeFramework.Application = Nothing

Dim objDocument As SolidEdgeFramework.SolidEdgeDocument = Nothing

Dim objPropertySets As SolidEdgeFramework.PropertySets = Nothing

Dim objProperties As SolidEdgeFramework.Properties = Nothing

Dim objProperty As SolidEdgeFramework.Property = Nothing

Dim i As Integer

Dim j As Integer

' Connect to a running instance of Solid Edge

objApplication = Marshal.GetActiveObject("SolidEdge.Application")

' Get a reference to the active document

objDocument = objApplication.ActiveDocument

' Get a reference to the document's property set collection

objPropertySets = objDocument.Properties

Dim IsPropThere As Boolean = False

' Get a reference to the Custom properties

For i = 1 To objDocument.Properties.count

objProperties = objPropertySets.Item(i)

If objProperties.Name = "Custom" Then

For j = 1 To objProperties.Count

objProperty = objProperties.Item(j)

If objProperty.Name = "StringToBeChecked" Then

Dim reply As DialogResult = MessageBox.Show("StringToBeChecked already found from Custom Properties. Overwrite?", "Caption", _

MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)

If reply = DialogResult.Yes Then

IsPropThere = False

Else

IsPropThere = True

End

End If

End If

Next j

End If

Next i

If IsPropThere = False Then

For i = 1 To objDocument.Properties.count

objProperties = objPropertySets.Item(i)

If objProperties.Name = "Custom" Then

Dim arvo As String

arvo = TextBox1.Text

For j = 1 To objPropertySets.Count

objProperty = objProperties.Item(j)

objProperty = objProperties.Add("StringToBeChecked", arvo)

IsPropThere = True

End

Exit Sub

Next j

End If

Next i

End If

End Sub

 

End Class

 

Posted by: Janne Heinonen
Post date: 12/17/2011 12:24:39 AM