Reply

Open existing draft in C#

[ Edited ]

 

I found a lot of usefull information on this forum but as newbie in C# I cannot open and close draft document. This is my code:

 

 

            SolidEdgeFramework.Application application = null;

            SolidEdgeFramework.Documents documents = null;

            SolidEdgeDraft.DraftDocument draft = null;

            Type type = null;

            type = Type.GetTypeFromProgID("SolidEdge.Application");

            application = (SolidEdgeFramework.Application)Activator.CreateInstance(type);

            application.Visible = true;

            application.DisplayAlerts = true;

            documents = application.Documents;

            draft = (SolidEdgeDraft.DraftDocument)documents.Add("SolidEdge.DraftDocument", "iso draft.dft");

            //draft = (SolidEdgeDraft.DraftDocument)documents.Open("C:\\xls\\documentname.dft", null, null, null, null, null);

            Thread.Sleep(8000);

            draft.Close(null, null, null); this should close opened draft file but I'm still not in this step

 

Appreciate any help.

 

Posted by: Mira Run
Post date: 11/29/2009 4:11:41 AM

8 REPLIES

RE: Open existing draft in C#

[ Edited ]

 

 

 

SolidEdgeFramework.Application application = null;

SolidEdgeFramework.Documents documents = null;

SolidEdgeDraft.DraftDocument draft = null;

Type type = null;

 

type = Type.GetTypeFromProgID("SolidEdge.Application");

application = (SolidEdgeFramework.Application)Activator.CreateInstance(type);

application.Visible = true;

application.DisplayAlerts = true;

documents = application.Documents;

draft = (SolidEdgeDraft.DraftDocument)documents.Add("SolidEdge.DraftDocument", "iso draft.dft");

draft = (SolidEdgeDraft.DraftDocument)documents.Open("C:\\xls\\documentname.dft", null, null, null, null, null); // this line makes error!!!! Any suggestions?

Thread.Sleep(8000);

draft.Close(null, null, null); this should close opened draft file but I'm still not in this step

 

 

Appreciate any help.

 

Posted by: Mira Run
Post date: 12/1/2009 9:56:28 PM

RE: Open existing draft in C#

[ Edited ]

 

Hi Autoit

---

yes, what a nasty one. I checked it out and on runtime you will get a TypeConflict error back from the COM pbject. As good programmers we browse the sdk help and find all these parameters in the documents.open method are of type object. Wow! What helps is always guessing. As a starting point i used the names for the parameters and as a result i produced the following code. It works for me to open painlessly an existing draft; hope it works for you too (please note: for the RevisionRuleType you need a reference to the revision manager).

 

            Object oDocRelationAutoServer = "";

            Object oAltPath = "";

            bool bRecognizeFeaturesIfPartTemplate = true;

            RevisionManager.RevisionRuleType rroRevisionRuleType = RevisionManager.RevisionRuleType.LastSavedType;

            bool bStopFileOpenIfRevisionRuleNotApplicable = false;

 

            string sDestinationFile = @"c:\scratch\00116508_151713_93.dft";

            _objDoc = (SolidEdgeDraft.DraftDocument)_solidEdge.Documents.Open(

                  sDestinationFile

                , oDocRelationAutoServer, oAltPath

                , bRecognizeFeaturesIfPartTemplate

                , rroRevisionRuleType

                , bStopFileOpenIfRevisionRuleNotApplicable);

 

 

 

Posted by: Holger Drozella
Post date: 12/7/2009 2:18:15 AM

RE: Open existing draft in C#

[ Edited ]

 

Hi Holdro and thank you for your reply. Will try your example how does it works. Will let you know.

 

Posted by: Mira Run
Post date: 12/10/2009 10:01:05 PM

RE: Open existing draft in C#

[ Edited ]

Hi Holdro,

 

As I'm not programmer it seems to me I will need more help. Your script shows me the next errors:

Error 1 The name '_objDoc' does not exist in the current context

Error 2 The name '_solidEdge' does not exist in the current context

I see that is like no declarations for this items. Isn't it? Appreciate your help. I will also try try how to solve this.

 

Posted by: Mira Run
Post date: 12/10/2009 10:14:02 PM

RE: Open existing draft in C#

[ Edited ]

 

Autoit,

 

I am not a C# expert, but it seems obvious to me, that the variables _objDoc and _application are of the same type as the variables draft and application in your code:

 

SolidEdgeFramework.Application _application;

SolidEdgeDraft.DraftDocument _objDoc;

 

Posted by: Martin Bernhard
Post date: 12/11/2009 10:50:50 AM

RE: Open existing draft in C#

[ Edited ]

As I'm really not programming expert I tried add at first row:

Object _objDoc;

 

and first error is gone

 

I cannot still continue and try to run programm. Second error is still there and I have no idea how to repair the code.

Last version of the code is:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

 

Object _objDoc;

Object oDocRelationAutoServer = "";

Object oAltPath = "";

bool bRecognizeFeaturesIfPartTemplate = true;

RevisionManager.RevisionRuleType rroRevisionRuleType = RevisionManager.RevisionRuleType.LastSavedType;

bool bStopFileOpenIfRevisionRuleNotApplicable = false;

 

string sDestinationFile = @"C:\draftname.dft";

_objDoc = (SolidEdgeDraft.DraftDocument)_solidEdge.Documents.Open(

sDestinationFile

, oDocRelationAutoServer, oAltPath

, bRecognizeFeaturesIfPartTemplate

, rroRevisionRuleType

, bStopFileOpenIfRevisionRuleNotApplicable);

 

}

}

}

 

Error 1 The name '_solidEdge' does not exist in the current context

 

Posted by: Mira Run
Post date: 12/11/2009 10:35:38 PM

RE: Open existing draft in C#

[ Edited ]

I was wrong in my last post. It should read:

 

"...the variables _objDoc and _solidEdge are of the same type as the variables draft and application in your code..."

 

SolidEdgeFramework.Application _solidEdge = null;

SolidEdgeDraft.DraftDocument _objDoc = null;

Type type = null;

 

type = Type.GetTypeFromProgID("SolidEdge.Application");

_solidEdge = (SolidEdgeFramework.Application)Activator.CreateInstance(type);

_solidEdge.Visible = true;

...

 

 

Posted by: Martin Bernhard
Post date: 12/14/2009 12:10:18 PM

RE: Open existing draft in C#

[ Edited ]

 

Happy New Year 2010 to all!

It works now. Thank you.

Final code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

 

            SolidEdgeFramework.Application _solidEdge = null;

            SolidEdgeDraft.DraftDocument _objDoc = null;

            Type type = null;

            type = Type.GetTypeFromProgID("SolidEdge.Application");

            _solidEdge = (SolidEdgeFramework.Application)Activator.CreateInstance(type);

            _solidEdge.Visible = true;

            Object oDocRelationAutoServer = "";

            Object oAltPath = "";

            bool bRecognizeFeaturesIfPartTemplate = true;

            RevisionManager.RevisionRuleType rroRevisionRuleType = RevisionManager.RevisionRuleType.LastSavedType;

            bool bStopFileOpenIfRevisionRuleNotApplicable = false;

            string sDestinationFile = @"C:\dftname.dft";

            _objDoc = (SolidEdgeDraft.DraftDocument)_solidEdge.Documents.Open(

                  sDestinationFile

                , oDocRelationAutoServer, oAltPath

                , bRecognizeFeaturesIfPartTemplate

                , rroRevisionRuleType

                , bStopFileOpenIfRevisionRuleNotApplicable);

        }

    }

}

 

Posted by: Mira Run
Post date: 1/1/2010 11:10:05 PM