Hey Folks,
i have a simple Question: How do i start a new drawing with API and a Custom Template.
I have a drawing template file with full path:"D:\\Temp\\A0_custom.slddrt" and a document Template: "drawing based 0.drwdot"
The drawing template has a title block on it and a Frame around the sheet. Normaly when i start a no drawing (without API)
then i select the "A0_custom" template and click Ok. A new drawing with my title block is started.
So now i want to do this by API:
'Generate a new Drawing
Dim drwDocument As sldworks.DrawingDoc
Dim drwTemplate As String = "D:\\Temp\\drawing based 0.drwdot"
Dim papTemplate As String = "D:\\Temp\\A0_custom.slddrt"
Dim Result As Boolean
'Create a new Drawing
drwDocument = _swApp.INewDocument2(papTemplate, swDwgPaperSizes_e.swDwgPapersUserDefined, 0, 0)
'Setup the Sheet
Result = drwDocument.SetupSheet5("Test1", swDwgPaperSizes_e.swDwgPapersUserDefined, _
swDwgTemplates_e.swDwgTemplateCustom, 1, 10, True, papTemplate, 0.2794, 0.2159, "Default", False)
Dim x As sldworks.ModelDoc2
x = _swApp.ActiveDoc
x.ForceRebuild3(False)
But after the code run through only a blank paper is on the screen, without my title block and the frame.
Why? Could you please tell me what is wrong in my code?
Tanks for help!
SolidworksApi macros
Thats very strange:
If i just started solidworks (no document open) the codeline
drwDocument = _swApp.INewDocument2(papTemplate, swDwgPaperSizes_e.swDwgPapersUserDefined, 0, 0)
do what i want. It starts a new Drawing with my title block, but if i do it again then i get a blank paper.
Also if i close every document i get the blank paper.
I think i don't understand solidworks
ok, i think i solved the problem myselfe:
I changed the code to
'Generate a new Drawing
Dim drwDocument As sldworks.DrawingDoc
Dim drwTemplate As String = "D:\Temp\drawing based 0.drwdot"
Dim papTemplate As String = "D:\Temp\A0_custom.slddrt"
Dim Result As Boolean
'Create a new Drawing
drwDocument = _swApp.INewDocument2(papTemplate, swDwgPaperSizes_e.swDwgPaperA0size, 0, 0)
Dim Sheet1 As sldworks.Sheet
Sheet1 = drwDocument.GetCurrentSheet
'Setup the Sheet
Result = drwDocument.SetupSheet5(Sheet1.GetName, swDwgPaperSizes_e.swDwgPaperA0size, _
swDwgTemplates_e.swDwgTemplateCustom, 1, 10, True, papTemplate, 0.2794, 0.2159, "Default", False)
Dim x As sldworks.ModelDoc2
x = _swApp.ActiveDoc
x.ForceRebuild3(False)
So i first get the Name of the Sheet which i want to setup.
And because it's a template for an A0 Paper i changed the ENum Papersize (swDwgPaperSizes_e.swDwgPaperA0size)