Reply

Expose Flat_Pattern_Model_CutSizeX

[ Edited ]

Hello all, I need to expose variables Flat_Pattern_Model_CutSizeX and Flat_Pattern_Model_CutSizeY which are created by system after flattening. In Tools->Variables I can see them and they are marked as Dim. When I try to search .psm via "COM Object Browser" then in

Document->Variables there are not these variables and I am not also abble to find them anywhere else. Can somebody help me where can I find these variables to Expose them? Thanks and Regards,

Jara

 

Posted by: Jara Ctverak
Post date: 8/17/2009 1:54:20 AM

7 REPLIES

RE: Expose Flat_Pattern_Model_CutSizeX

[ Edited ]

 

Hi Jara,

 

I have written code exposing these variables before. I used the Variables->Query method passing in the name of the variable. I used the locale-specific name for the method call (german: Abwicklung_x_Schnittgröße instead of Flat_Pattern_Model_CutSizeX) but it may work with the internal name. from there I set the Expose member to true. You will need to use late binding for the variable methods as the VariableList does not always hold Variable objects.

Here's some C++ code (let me know if you need an example in a different language):void CProperties::ExposeVariable(SolidEdgeDocumentPtr doc, _bstr_t variableName, _bstr_t propertyName){ /* Get the variables collection and query for the name */ VariablesPtr variables = NULL; HRESULT hr = doc->Variables->QueryInterface(&variables); if (FAILED(hr)) _com_issue_error(hr); VariableListPtr results = NULL; hr = variables->Query(variableName)->QueryInterface(&results); if (FAILED(hr)) _com_issue_error(hr); /* See if we found it... */ if (results->Count == 1) { /* Have to do this next bit with IDispatch - ughhh */ IDispatchPtr var = results->Item(1L); /* Try and expose the variable */ DISPID dispid; _variant_t arg; DISPID dispidNamed = DISPID_PROPERTYPUT; LPOLESTR memberName(L"Expose"); DISPPARAMS getparams = { NULL, NULL, 0, 0 }; DISPPARAMS putparams = { NULL, &dispidNamed, 1, 1 }; hr = var->GetIDsOfNames(IID_NULL, &memberName, 1, LOCALE_SYSTEM_DEFAULT, &dispid); if (FAILED(hr)) _com_issue_error(hr); /* Check the value first */ _variant_t result; hr = var->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, &getparams, &result, NULL, NULL); if (FAILED(hr)) _com_issue_error(hr); bool nonBoolean = ((result.vt != VT_BOOL) && (result.vt != VT_I4)); if (nonBoolean || (result.boolVal == VARIANT_FALSE)) { /* Check if the property exists before setting the value. Exposed variables are * always added to the custom property set. */ PropertySetsPtr propertySets = NULL; PropertiesPtr customProperties = NULL; try { hr = doc->Properties->QueryInterface(&propertySets); if (SUCCEEDED(hr)) /* If we failed here then we just fall through and set the value... */ { _variant_t custom(L"Custom"); customProperties = propertySets->Item(custom); PropertyPtr prop = customProperties->Item(propertyName); /* If we get this far then the property exists */ prop->Delete(); } } catch (_com_error) { /* Just ignore this - it is probably due to the property not being in the * property set, and if not then we should just try and set the value and * see what happens. */ } /* Now set the Exposed property */ arg = _variant_t(VARIANT_TRUE); putparams.rgvarg = &arg; hr = var->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYPUT, &putparams, NULL, NULL, NULL); if (FAILED(hr)) _com_issue_error(hr); } /* Now set the property name to use */ memberName = LPOLESTR(L"ExposeName"); hr = var->GetIDsOfNames(IID_NULL, &memberName, 1, LOCALE_SYSTEM_DEFAULT, &dispid); if (FAILED(hr)) _com_issue_error(hr); /* Check the current value */ hr = var->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, &getparams, &result, NULL, NULL); if (FAILED(hr)) _com_issue_error(hr); if ((result.vt != VT_BSTR) || (_wcsicmp(static_cast (result.bstrVal), static_cast (propertyName)) != 0)) { arg = _variant_t(propertyName); putparams.rgvarg = &arg; hr = var->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYPUT, &putparams, NULL, NULL, NULL); if (FAILED(hr)) _com_issue_error(hr); } if (FAILED(hr)) _com_issue_error(hr); }}

Cheers

Calum

 

Posted by: Calum McLellan
Post date: 8/17/2009 9:55:08 PM

RE: Expose Flat_Pattern_Model_CutSizeX

[ Edited ]

 

Hi Calum,

Thank you very much. Please do you have this example also in C#?

Regards,

Jara

 

 

 

Posted by: Jara Ctverak
Post date: 8/18/2009 9:25:25 PM

RE: Expose Flat_Pattern_Model_CutSizeX

[ Edited ]

If you have Flat Pattern code in VB.NET then please send it to me

Any help regards to this is pleased!

 

Posted by: Sandeep Shewale
Post date: 8/18/2009 10:42:37 PM

RE: Expose Flat_Pattern_Model_CutSizeX

[ Edited ]

 

Hi Guys,

sorry it took so long - I've been on holiday. Here's an example in C# and VB.Net:

C#:using System;using System.Runtime.InteropServices;using System.Reflection;namespace ConsoleApplication1{ class Program { static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.SolidEdgeDocument document = null; SolidEdgeFramework.Variables variables = null; try { /* Connect to a running instance of Solid Edge */ application = (SolidEdgeFramework.Application) Marshal.GetActiveObject("SolidEdge.Application"); /* Get a reference to the active document */ document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; /* Get a reference to the variables collection */ variables = (SolidEdgeFramework.Variables)document.Variables; /* Perform a case-insensitive query for the variable */ SolidEdgeFramework.VariableList variableList = (SolidEdgeFramework.VariableList)variables.Query("TestVar", Type.Missing, Type.Missing, true); /* Check if we found the variable and expose it */ if (variableList.Count == 1) { object variable = variableList.Item(1); try { /* Check if the variable is exposed (we get an integer instead of a boolean * here, so check for 0) */ object exposed = variable.GetType().InvokeMember( "Expose", BindingFlags.GetProperty, null, variable, null); if ((int)exposed == 0) { /* Expose the variable and set the name */ variable.GetType().InvokeMember("ExposeName", BindingFlags.SetProperty, null, variable, new object[] { "TestName" }); variable.GetType().InvokeMember("Expose", BindingFlags.SetProperty, null, variable, new object[] { true }); } } finally { if (variable != null) { Marshal.ReleaseComObject(variable); variable = null; } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { if (variables != null) { Marshal.ReleaseComObject(variables); variables = null; } if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } } }}

 

VB.Net:Imports System.Runtime.InteropServicesModule Module1 Sub Main() Dim application As SolidEdgeFramework.Application = Nothing Dim document As SolidEdgeFramework.SolidEdgeDocument = Nothing Dim variables As SolidEdgeFramework.Variables = Nothing Try ' Connect to a running instance of Solid Edge application = DirectCast( _ Marshal.GetActiveObject("SolidEdge.Application"), SolidEdgeFramework.Application) ' Get a reference to the active document document = DirectCast(application.ActiveDocument, SolidEdgeFramework.SolidEdgeDocument) ' Get a reference to the variables collection variables = DirectCast(document.Variables, SolidEdgeFramework.Variables) ' Perform a case-insensitive query for the variable Dim variableList As SolidEdgeFramework.VariableList = _ DirectCast(variables.Query("TestVar", , , True), SolidEdgeFramework.VariableList) ' Check if we found the variable and expose it If variableList.Count = 1 Then Dim variable As Object = variableList.Item(1) Try ' Check if the variable is exposed (we get an integer instead of a boolean ' here, so check for 0) If (DirectCast(variable.Expose, Integer) = 0) Then ' Expose the variable and set the name variable.ExposeName = "TestName" variable.Expose = True End If Finally If variable Is Nothing Then Marshal.ReleaseComObject(variable) variable = Nothing End If End Try End If catch ex as Exception Console.WriteLine(ex.Message) Finally If variables Is Nothing Then Marshal.ReleaseComObject(variables) variables = Nothing End If If document Is Nothing Then Marshal.ReleaseComObject(document) document = Nothing End If If application Is Nothing Then Marshal.ReleaseComObject(application) application = Nothing End If End Try End SubEnd Module

Cheers

Calum

 

Posted by: Calum McLellan
Post date: 9/3/2009 1:27:17 AM

RE: Expose Flat_Pattern_Model_CutSizeX

[ Edited ]

Thank you Calum!

 

Wonderful! It works!

 

Jara

 

Posted by: Jara Ctverak
Post date: 9/4/2009 12:51:16 AM

Re: RE: Expose Flat_Pattern_Model_CutSizeX

Hi, somebody have example this problem in VB.net ? thanks

Re: RE: Expose Flat_Pattern_Model_CutSizeX

Its already out there in VB.Net