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);
}
}
Hi Orcun Cakmak ,
I have no solution for this behaviour but I can confirm this behavior on Solidworks 2019 SP5:
When using
swApplication.UserControl = false;
swApplication.Visible = false;
SolidWorks.Interop.sldworks.IView firstView = swDrawing.CreateDrawViewFromModelView3(@"C:\temp\IKKE.sldprt", "*Front", 0, 0, 0) as SolidWorks.Interop.sldworks.IView;
firstView is null when visible = false and no drawing view is made, but works fine if visible = true
I would suggest to make a feature request at https://customerportal.solidworks.com/ and make a SPR.
You will probably be asked for a minimal working example and it is strongly advised to attach one, because this helps in getting faster attention to your issue. You can provide a link to his page also.
Also, Please post the SPR number as a link back here.
It is a know shortcoming that some API functions don't work if Solidworks is invisible. But since it worked for you in the past, it can be worth the effort to ask from feedback from solidworks corp.
Eddy