Problem with documents.add method.

Experimenter
Experimenter

In the help file, the syntax shown is 

 

Public Function Add( _

   Optional ByVal ProgID As Variant, _

   Optional ByVal TemplateDoc As Variant _

) As Object

 

The second parameter is causing confusion. I haven't seen a single example which uses the second paramenter.

 

If I give a path (as suggested by tooltip on TemplateDoc) it gives an error. Its very confusing.

 

How  can we use the second parameter and when?

7 REPLIES

Re: Problem with documents.add method.

Phenom
Phenom

The second parameter for template is optional and can be omitted.

If you want to create a new document using a specific template, then specify the full path of the template.

what error are you getting ?

 

Re: Problem with documents.add method.

Experimenter
Experimenter

Parameter being optional is not the issue, but when we need to provide this and how?

 

Path gives the following error

 

Unable to cast COM object of type 'System.__ComObject' to interface type 'SolidEdgePart.PartDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{23C52E80-4698-11CE-B307-0800363A1E02}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

Re: Problem with documents.add method.

Siemens Valued Contributor Siemens Valued Contributor
Siemens Valued Contributor

This sample gave me no issues when I tried. What arguments are you passing in?

Dim m_oSolidEdgeApplication As SolidEdgeFramework.Application = Nothing
Dim m_oSolidEdgePart As SolidEdgePart.PartDocument = Nothing

m_oSolidEdgeApplication = CType(CreateObject("SolidEdge.Application"), SolidEdgeFramework.Application) m_oSolidEdgeApplication.Visible = True m_oSolidEdgeApplication.DisplayAlerts = False m_oSolidEdgePart = m_oSolidEdgeApplication.Documents.Add("SolidEdge.PartDocument", "C:\Program Files\Solid Edge ST10\Template\ANSI Metric\ansi metric part.par")
Siemens PLM Software, Inc.
Project Test Engineer (Automation)

Re: Problem with documents.add method.

Experimenter
Experimenter

I am using exactly similar code but getting error as mentioned in my previous post.

Re: Problem with documents.add method.

Siemens Valued Contributor Siemens Valued Contributor
Siemens Valued Contributor
I was able to get the same error if I used a template that was not a .par document. Could that be the issue?
Siemens PLM Software, Inc.
Project Test Engineer (Automation)

Re: Problem with documents.add method.

Siemens Valued Contributor Siemens Valued Contributor
Siemens Valued Contributor

Hi @NirantarVidyart,

 

Can you please share your code?

Re: Problem with documents.add method.

Phenom
Phenom

Without disclosing your code, check if the template file exists using System.IO.File.Exists

and also if the string in the first argument is seplled correctly.