Executing a View->Fit on BeforeDocumentSave

In 3D environments, my Fit command doesn't seem to be "sticking". When I close the part (for example) and re-open it, it looks as it did before the Fit command.

 

Here is part of my code (FitView() is called from BeforeDocumentSave):

 

Private Sub FitView()

Dim theEdge As SolidEdgeFramework.Application

Try

theEdge = Marshal.GetActiveObject("SolidEdge.Application")

Catch ex As Exception

MsgBox("Error connecting to Solid Edge", MsgBoxStyle.OKOnly)

Exit Sub

End Try

 

Try

Select Case theEdge.ActiveDocumentType

Case SolidEdgeConstants.DocumentTypeConstants.igAssemblyDocument

theEdge.StartCommand(33022)

Case SolidEdgeConstants.DocumentTypeConstants.igPartDocument, _

SolidEdgeConstants.DocumentTypeConstants.igSheetMetalDocument, _

SolidEdgeConstants.DocumentTypeConstants.igWeldmentDocument

theEdge.StartCommand(32821)

Case SolidEdgeConstants.DocumentTypeConstants.igDraftDocument

theEdge.StartCommand(10202)

Case Else

 

End Select

Catch ex As Exception

MsgBox("Unable to determine document type.", MsgBoxStyle.Exclamation, "FitView")

Finally

theEdge = Nothing

If Not (theEdge Is Nothing) Then

Marshal.ReleaseComObject(theEdge)

End If

End Try

End Sub

 

After this runs, I run a routine to update the mass, it the resulting mass is correct upon re-opening the part, and it appears that the Save was successful (changes were kept). The only thing not reflected in the file when re-opened is the Fit command.

 

Any ideas?

 

Posted by: Michael Frayser
Post date: 10/4/2005 11:11:55 AM

10 REPLIES

RE: Executing a View->Fit on BeforeDocumentSave

I tried substituting StartCommand(40229) which is hide all ref planes for the StartCommand(32821) in the part environment. It does the same thing. I can see it execute on the screen, but it didn't "stick" with the save, almost like it was executed after the save.

 

Posted by: Michael Frayser
Post date: 10/5/2005 2:15:17 AM

RE: Executing a View->Fit on BeforeDocumentSave

Michael,

 

This code works for me. I only tested a part file but it should work in the other environments also.

 

 

Imports System.Runtime.InteropServices

 

Module Module1

Sub Main()

Dim objApp As SolidEdgeFramework.Application

Dim objDocument As SolidEdgeFramework.SolidEdgeDocument

 

objApp = Marshal.GetActiveObject("SolidEdge.Application")

objDocument = objApp.ActiveDocument

 

If Not (objDocument Is Nothing) Then

Select Case objApp.ActiveDocumentType

Case SolidEdgeFramework.DocumentTypeConstants.igAssemblyDocument

objApp.StartCommand(SolidEdgeConstants.AssemblyCommandConstants.AssemblyViewFit)

Case SolidEdgeFramework.DocumentTypeConstants.igDraftDocument

objApp.StartCommand(SolidEdgeConstants.DetailCommandConstants.DetailViewFit)

Case SolidEdgeFramework.DocumentTypeConstants.igPartDocument

objApp.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewFit)

Case SolidEdgeFramework.DocumentTypeConstants.igSheetMetalDocument

objApp.StartCommand(SolidEdgeConstants.SheetMetalCommandConstants.SheetMetalViewFit)

Case SolidEdgeFramework.DocumentTypeConstants.igWeldmentDocument

objApp.StartCommand(SolidEdgeConstants.WeldmentCommandConstants.WeldmentViewFit)

End Select

objDocument.Close(True)

End If

End Sub

End Module

 

 

Posted by: Jason Newell
Post date: 10/5/2005 2:19:15 AM

RE: Executing a View->Fit on BeforeDocumentSave

Yes, this works when ran as a macro, but in the context of an addin, particularly the BeforeDocumentSave event, the view setting doesn't seem to get saved. I'll attach my code.

 

Thanks,

Mike

 

 

Posted by: Michael Frayser
Post date: 10/5/2005 3:05:09 AM

RE: Executing a View->Fit on BeforeDocumentSave

Ah, an addin, you didn't say that .

 

It makes sense to me now. I bet commands aren't processed at that point in the event heirarchy .

 

I bet I can fix this problem. I'll do some hacking at lunch today CST and show you how it do it .

 

 

 

Posted by: Jason Newell
Post date: 10/5/2005 3:09:19 AM

RE: Executing a View->Fit on BeforeDocumentSave

Hey, I'm in the Addin forum. It was implied!

 

I will mention this. The ViewFit in the draft environment sticks. It's only in 3D that there is a problem.

 

Thanks for the help.

 

Posted by: Michael Frayser
Post date: 10/5/2005 5:37:37 AM

RE: Executing a View->Fit on BeforeDocumentSave

Problem solved! This is in C# but you should get the gist. Let me know how it goes .

 

 

public void BeforeDocumentSave(object theDocument)

{

SolidEdgeFramework.Window window = (SolidEdgeFramework.Window)this.application.ActiveWindow;

window.View.Fit();

Marshal.ReleaseComObject(window);

window = null;

GC.Collect();

}

 

 

Posted by: Jason Newell
Post date: 10/5/2005 6:14:56 AM

RE: Executing a View->Fit on BeforeDocumentSave

This one works! Is there a similar trick for setting the view to Isometric and hiding reference planes? I haven't been able to get these to work either.

 

Thanks,

Mike

 

 

Posted by: Michael Frayser
Post date: 10/6/2005 1:24:46 AM

RE: Executing a View->Fit on BeforeDocumentSave

Never satisified

 

Yeah, I'll look at it tonight and see what I can come up with. I might have an idea that might actually work .

 

Posted by: Jason Newell
Post date: 10/6/2005 12:40:07 PM

RE: Executing a View->Fit on BeforeDocumentSave

OK, that took me like 5 minutes .

 

Using Solid Edge Spy, I can see that BeforeCommandRun(PartFileSave) is called BEFORE BeforeDocumentSave. Try and to set the view state before then and see how it goes.

 

Posted by: Jason Newell
Post date: 10/6/2005 12:46:04 PM