AnsweredAssumed Answered

CreateDrawViewFromModelView3 returning null if application.visibility is false

Question asked by Orcun Cakmak on Aug 26, 2020
Latest reply on Aug 28, 2020 by Eddy Alleman

I would appreaciate any help.

 

This exact code works with Solidworks 2018 SP 5 and earlier, but anything after that does not work properly. Currently trying this on Solidworks 2020 SP 4.

 

The code itself , starts with all work around to deal with grabbing solidworks application, the rest is very simple drawing generation. 

 

Problem:

   -CreateDrawViewFromModelView3 returns null.

 

Preconditions: 

   ** C:\ABCTEMP\seal_beam_dis_perde.sldprt exist and proper solidworks part file.

 

public void sampleStart() {
mevcutSLDWORKS();
GC.Collect();
GC.WaitForPendingFinalizers();
this.swApplication = (SldWorks.SldWorks)Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application.28"));
this.swApplication.Visible = false;
kapamaDene(swApplication);
createDrawing(swApplication);
}

public void createDrawing(SldWorks.SldWorks swApplication)
{
ModelDoc2 swModel = (ModelDoc2)swApplication.OpenDoc6("C:\\ABCTEMP\\seal_beam_dis_perde.sldprt", (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
DrawingDoc swDrawing = swApplication.NewDrawing2((int)swDwgTemplates_e.swDwgTemplateA3size, "test", (int)swDwgPaperSizes_e.swDwgPaperA3size, 0, 0);
View firstView = swDrawing.CreateDrawViewFromModelView3(swAsModel.GetPathName(), "*Front", 0, 0, 0);
//firstView is null if swApplication.Visible = false, but properly point to the view if done with swApplication.Visible = true;


}



public void mevcutSLDWORKS()
{
try
{
Process[] processes = Process.GetProcessesByName("SLDWORKS");
foreach (Process process in processes)
{
process.CloseMainWindow();
process.Kill();
}
}
catch (Exception exc)
{

}
}
public void kapamaDene(SldWorks.SldWorks appli)
{
try
{
appli.CloseAllDocuments(true);
}
catch (Exception e)
{
Debug.Print(e.StackTrace);
}
}

Outcomes