Jump to content

Recommended Posts

Posted

hey guys forgive me but i cant work out how to create a NEW drawing through using lisp.

 

Tha new command doesnt work.

 

How can i create a new drawing through lisp??

Posted

For example:

 

(defun c:newdoc()
(vl-load-com)
  (vla-Activate
    (vla-Add
      (vla-get-Documents
        (vlax-get-acad-object))))
 ); end of c:newdoc

Posted

ok...

thank you

 

how would you go about doing this if you wanted to use an existing template asmi?

Posted

You can define some function like this:

 

(defun Create_New_Document(Template Activate / dCol nDoc)
 
(vl-load-com)

 (setq dCol(vla-get-Documents
            (vlax-get-acad-object)))
 (if(not
      (vl-catch-all-error-p
 (setq nDoc
   (vl-catch-all-apply 'vla-Add
     (list dCol Template)))))
   (if Activate
     (vla-Activate nDoc)
     ); end if
   (setq nDoc nil)
   ); end if
 nDoc
); end of Create_New_Document

 

And call it with arguments you need. For example:

 

(Create_New_Document "ISO A2 -Named Plot Styles.dwt" T)

 

will to create document on base of "ISO A2 -Named Plot Styles.dwt" and activate it.

 

(Create_New_Document "" nil)

 

Will to create document on base of Default template and stay in inactive. Funcion returns ActiveX Object of the newly created document.

Posted

Thank you very much once again.

 

Nice little routine.

Posted

I've got one that will work in VBA, if interested?

 

ML

  • 2 weeks later...
Posted

ML

 

YES PLEASE,

 

im actually going to write all new routines within VBA so it would help so much if you could supply me with this part.

 

Thank you

Posted

Just a quick note. When adding a new document in vb, make sure your SDI mode is not on.

Posted

Hi Russell,

Here is The VBA code that I wrote.

It seems to be working well.

Please type in the dwt file that you would like to use, by default, below the blue text.

 

Also, I have code that will prompt for a Saveas

 

After you try it, if you do not want the Saveas part, then just delete every thing below ***SAVEAS***

 

Also, Borgunit raises a good point.

In Vanilla ACAD, SDI should be set to 0, by default.

If you get an error saying that 2 drawings can not be opened at once, then let me know. We can set SDI to 0, then back to 1 at the end, if necessary. It has not been an issue for me.

 

ML

 

Sub NewDwg()
Dim WshNetwork As Variant, Username  As Variant
Dim Preferences As AcadPreferences
Dim TempFilePathCurr As String
Dim TempFilePathDef As String

Set WshNetwork = CreateObject("WScript.Network")
Username = WshNetwork.Username

If Documents.Count < 1 Then
 MsgBox "A drawing must be open, create a new drawing"
 Exit Sub
End If
Set Preferences = ThisDrawing.Application.Preferences
'Current drawing template file location
TempFilePathCurr = Preferences.Files.TemplateDwgPath

'AutoCAD default template file location
'[color=red]Adjust path to your version[/color] 
TempFilePathDef = "C:\Documents and Settings\" & Username & "\Local Settings\Application Data\Autodesk\AutoCAD 2009\R17.2\enu\Template"

[color=blue]'Replace string with your template name[/color]
Documents.Add TempFilePathDef & "acad.dwt"

'Make sure that the temlate path is set back to what it was originally set to
Preferences.Files.TemplateDwgPath = TempFilePathCurr

'***SAVEAS***
If MsgBox("Would you like to save this drawing?", vbYesNo) = vbYes Then
 GoTo SaveAs
Else
 ThisDrawing.Close
 Exit Sub
End If

SaveAs:
Dim intReturn As Variant
Set objDialog = CreateObject("SAFRCFileDlg.FileSave")

objDialog.FileName = ThisDrawing.Name
objDialog.FileType = "AutoCAD 2004 Drawing(*.dwg)"
intReturn = objDialog.OpenFileSaveDlg

If intReturn Then
 On Error GoTo Errorhandler
'Get the filename entered into the saveas dialog box
 ThisDrawing.SaveAs objDialog.FileName, ac2004_dwg
Else
 ThisDrawing.Close
 Exit Sub
End If

Posted

Can I just ask why you would use a lisp to open a new drawing?

 

Why dont you just click on the new drawing icon and select your own pre-set template.

 

 

AHHHH, it has just came across me, are you using a lisp to automatically open your own template file?

Posted

I dont understand the use of lisp for this purpose either..Even if you want your own template to open everytime you start a new drawing, all you have to do is change your options..

Posted

> smorales02

 

I dont understand the use of lisp for this purpose either..Even if you want your own template to open everytime you start a new drawing, all you have to do is change your options..

 

> stevsmith

Can I just ask why you would use a lisp to open a new drawing?

 

Why dont you just click on the new drawing icon and select your own pre-set template.

 

 

AHHHH, it has just came across me, are you using a lisp to automatically open your own template file?

 

Opening of a new file can be used for many purposes. Usually this file remains inactive and in it created something on the basis of other drawings. For example bill of materials or scaled to metric/imperial copy of other drawing or something else. Sometimes such files are activated in the end of work, but is more often automatically saves and closes. Often it is used at batch operation of files.

Posted

I definately couldn't have put it better myself.

 

Thank you Asmi.

 

Also thank you for the vba ML.

 

i originally used your lisp routine asmi and it works great.

But i'm trying to write all new little apps in Vba .

 

Thank you guys

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...