How do I use C# to extract custom properties within a .psm file?

Valued Contributor
Valued Contributor

This is my first attempt to write any code for SE. My skills are very null... How do I extract a few custom properties out of a psm or asm file so I can write them to a txt file?

 

I have been over the sample package from Codeplex. It very useful but I can not find my answer there. If I had more experience I am sure I would have found It.

 

Any help would be great.

Nathan 

Nathan M. Gardner

https://www.etsy.com/people/NathanMGardner

Be sure to check out my work!!
Made in Maine Wood Carvings

7 REPLIES

See this code: //----------------------------------------...

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

See this code:

//--------------------------------------------------------------------------
// Read all custom properties of a Solid Edge document
//--------------------------------------------------------------------------
SolidEdgeFramework.SolidEdgeDocument pDoc = (SolidEdgeFramework.SolidEdgeDocument)pSEApp.ActiveDocument;
SolidEdgeFramework.PropertySets pPropSets = (SolidEdgeFramework.PropertySets)pDoc.Properties;
SolidEdgeFramework.Properties pCustomProps = pPropSets.Item("Custom");
foreach (SolidEdgeFramework.Property pProp in pCustomProps)
{
  Console.WriteLine("Property:  {0} = {1}", pProp.Name ,pProp.get_Value().ToString());
}

 

Re: See this code: //----------------------------------------...

Valued Contributor
Valued Contributor
I do not know how to get around this.

it is erroring out with " 'pSEApp' does not exist in the current context "
what do I need to reference to use the " pSEApp.Activ​eDocument "
Nathan M. Gardner

https://www.etsy.com/people/NathanMGardner

Be sure to check out my work!!
Made in Maine Wood Carvings

Re: See this code: //----------------------------------------...

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom
Sorry, I assumed that you already have that minimum knowledge on how to get a pointer to the Solid Edge application.
The following lines of code will do that for you:
[CODE]
SolidEdgeFramework.Application pSEApp = null;
try
{
// Attempt to connect to Solid Edge.
pSEApp = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");
}
catch (Exception)
{
MessageBox.Show("Solid Edge is not started.");
}
[/CODE]
To get this code working correctly, you should also implement the OleMessageFilter interface. The best start for you, would be to download the SDK API Samples and just replace the specific macro code by your code.

Re: See this code: //----------------------------------------...

Valued Contributor
Valued Contributor
Thank you Martin, I will give that a try.
Nathan M. Gardner

https://www.etsy.com/people/NathanMGardner

Be sure to check out my work!!
Made in Maine Wood Carvings

Re: See this code: //----------------------------------------...

Valued Contributor
Valued Contributor
Thank you very much. I was able to get it to work and write out all properties. Now how do I pull out just one or two of the known properties? I want to pull out just _ProjectName from the list below, which is a custom property.

Property: Density = 0.283 lbm/in^3

Property: Accuracy = 0.99

Property: Material Thickness = 0.060 in

Property: Bend Radius = 0.043 in

Property: Relief Width = 0.062 in

Property: Relief Length = 0.050 in

Property: Neutral Factor = 0.38

Property: Minimum Arc Length = 0.005 in

Property: Deviational Tolerance = 0.005 in

Property: _ProjectName = INCUBATOR PROTOTYPE

Property: SE Title = Fab, Bridge

Property: SE Desc = Inner Chamber Seperator

Property: sqfeet = 0.455 ft^2

Property: _Status = 3

Property: xd_ProgID =

Property: TemplateUrl =




How do I post code to show up in its own window?
Nathan M. Gardner

https://www.etsy.com/people/NathanMGardner

Be sure to check out my work!!
Made in Maine Wood Carvings

Re: See this code: //----------------------------------------...

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom
Use this:
SolidEdgeFramework.Property pProp = pCustomProps.Item("_ProjectName");

The code block is only supported when writing a new post or answer, but cannot be used in a comment ;-(

Re: See this code: //----------------------------------------...

Valued Contributor
Valued Contributor
Thanks again, I got it working.
Nathan M. Gardner

https://www.etsy.com/people/NathanMGardner

Be sure to check out my work!!
Made in Maine Wood Carvings