Cancel
Showing results for 
Search instead for 
Did you mean: 

SE-Visual Basic- How to add opened, not active file to draft object?

Valued Contributor
Valued Contributor

Hello

 

I have problem with simple VB code for SE.

 

I need to make operation "Save as" for opened draft file, but this file is not activated (I mean, that few others files in SE are opened in the same time).

 

I can't find way to add file to draft object. Could you help me?

 

There is code with problem:

 

Sub 
Dim objApplication As SolidEdgeFramework.Application = Nothing
Dim objDocuments As SolidEdgeFramework.Documents = Nothing
Dim objDraft As SolidEdgeDraft.DraftDocument = Nothing

 

Try

OleMessageFilter.Register()
objApplication = Marshal.GetActiveObject("SolidEdge.Application")
objDocuments = objApplication.Documents

 

 

'HERE IS PROBLEM

' I try to use function "Save as" but how to add not activated file to objDraft?

'I can do it by this step:

 

objDraft =  objDocuments.Open("File")

 

'And this wok properly, but I must open the file, which is opened. I think that should be other way, but I can't find it.

 


objDraft.SaveAs("File2")

 

 

Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
OleMessageFilter.Revoke()
End Try

End Sub

 

Thank for help.

 

6 REPLIES

Re: SE-Visual Basic- How to add opened, not active file to draft object?

Valued Contributor
Valued Contributor

Hi @Rektim

You can download and reverse engineer this solution:

    https://www.dropbox.com/s/fhgmdttsuqwct78/goRipDelta.zip?dl=0

This is for a simple command line tool I have written. However this should show you how to deal with different Solid Edge documents, and how to connect to the active one.

You will have more success posting this question to the "Solid Edge Developer Forum". There is some pretty good info there and those on that forum are always willing to help. Unlike me they may give you a direct answer.

PS: If you are not familiar with SESpy, then get it! It is an incredible piece of software you must master.

Cheers

 

Re: SE-Visual Basic- How to add opened, not active file to draft object?

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

Hi @pieter_nienaber

 

Is it possible to download the file without signing into dropbox ?

 

@Rektim

As mentioned in previous reply, the Solid Edge Developer Forum is the right place to ask API related questions.

   

To answer your question in this thread, try using something like this:

   

Dim objDraft As SolidEdgeDocument = objDocuments.Item("File")
objDraft.SaveAs("File2")

Also note using SolidEdgeDocument as the type for objDraft.

This will allow you to assign any type of document to objDraft.

Though this is not absolutely necessary in your case.

If you are sure "File" is a draft document, you can use DraftDocument.

 

Re: SE-Visual Basic- How to add opened, not active file to draft object?

Valued Contributor
Valued Contributor

Thanks for answers.

 

Next time I will make post in Developer Forum.

 

Unfortunatelly file from pieter_nienaber did not help me. 

I don't see there solution for my problem. 

Way proposed by Tushar also don't work.

 

I know how  connect to active document- this is not problem. But I don't know how to connect to not active document.

I.e. in SE session three file are opened- part, assembly and draft (target file). Active file is part or assembly. And in this situation I must "Save as" draft file. I have to find it -  I know name of this file- and make operation on it.

So, I can make this draft file active- but I don't know how. Simple idea: objDocuments.Item("FileName").Activate is not available. 

 

I can connect objDraft to this file, but I can't find way to do it. Simple idea:  objDraft=objDocuments.Item(filename), don't work.

 

If I know "number" of this file in documents collection I can do objDraft=objDocuments.Item(fileNumber) and this is OK.

But I don't know the number. I can scan all documents and check its name, i.e.:

for i =1 to objDocuments.Count

if objDocuments.Item(i).NAME=FileName then objDraft= objDocuments.Item(i)

next

 

But there is not possibility to read name of documents in collection.

 

 

 

PS

If moderator has possibility to move this post on correct forum?

 

PS2

I don't know SESpy, I will check it. I have started work with VB in SE yestarday. In the past I 've used VB in Excel.

 

I don't see any way to veryfy/check collection of opened documents- name of file, path etc. 

 

 

Re: SE-Visual Basic- How to add opened, not active file to draft object?

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

All methods that you are thinking of and those you have rejected outright are in fact possible.

I have posted the code only after testing.

You need to check if you are using the full name of "File" including its path and extension.

Let me know if you need the source files, I'd be gald to share.

Re: SE-Visual Basic- How to add opened, not active file to draft object?

Valued Contributor
Valued Contributor

I solved this problem by:

 

Dim objApplication As SolidEdgeFramework.Application = Nothing
Dim objDocuments As SolidEdgeFramework.Documents = Nothing
Dim objDocument As SolidEdgeFramework.SolidEdgeDocument = Nothing
Dim objDraft As SolidEdgeDraft.DraftDocument = Nothing

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

objDocument = objDocuments.Item("File1") 'With "Document" it is work, and I can add file1. I didn't notice different between SolidEdgeFramework.Documents and SolidEdgeFramework.SolidEdgeDocument


objDraft = objDocument 
objDraft.Activate()

 

objDraft.SaveAs("File2")

 

 

Thanks for help.

Re: SE-Visual Basic- How to add opened, not active file to draft object?

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

No need to Activate, it will 'Save As' even without.