Author Topic: new from template  (Read 3903 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
new from template
« on: March 24, 2008, 06:06:00 PM »
OK, I looked and couldn't find anything so here goes.  Does anyone know of a way to call this routine from Acad and pass a template name?
Code: [Select]
Public Sub makenewdwg(dsh As String)
Application.Documents.Add dsh
End Sub

I tried this
Code: [Select]
Public Sub qnewdwg()
makenewdwg "coversheet"
End Sub
whcih does work, but I dont want to make 5 subs where the only thing different is the template name.  I am hoping for a way to call "makenewdwg" and pass the argument directly.  I hope this makes sense
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Bryco

  • Water Moccasin
  • Posts: 1883
Re: new from template
« Reply #1 on: March 24, 2008, 08:15:46 PM »
I never could figure out how to do that directly from a menu, which is I presume similar to what you are doing,  so the 5 subs don't take too long to make. I had 100's so I wrote a sub to write all the subs.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: new from template
« Reply #2 on: March 24, 2008, 09:28:07 PM »
This works from the command line, should work in a menu as well:
Code: [Select]
(command "vbastmt" "makenewdwg \"acad\"")
substitute the acad with your template name.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: new from template
« Reply #3 on: March 25, 2008, 09:50:55 AM »
Well done Jeff.
What language is that?

Guest

  • Guest
Re: new from template
« Reply #4 on: March 25, 2008, 10:20:53 AM »
Well done Jeff.
What language is that?

That's LSP with a little VBA thrown into the mix.   VBASTMT - VBA Statement

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: new from template
« Reply #5 on: March 25, 2008, 11:35:13 AM »
Very nice!!  I was trying to use vbastmt, but kept getting syntax errors and couldn't figure out how to make it work.  the \" was my problem, I didn't have the \
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: new from template
« Reply #6 on: March 25, 2008, 11:52:09 AM »
OK, whats the trick?  I cant seem to make it work
Quote
Command: (command "vbastmt" "makenewdwg \"UES\"")
vbastmt
Expression: makenewdwg "UES"
Syntax Error

Command: nil
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: new from template
« Reply #7 on: March 25, 2008, 12:31:57 PM »
They key is that the template must be a DWT file and either located in your specified Template locate OR the exact path included. Also, make sure your DVB with the makenewdwg Sub is loaded.

I got the same error as you when I tried to run it without having loaded the macro first.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: new from template
« Reply #8 on: March 25, 2008, 01:39:14 PM »
No need to make a sub just for that one line, as you can just type that in as the statement.

Code: [Select]
(command "_.vbastmt" "Application.Documents.Add(\"DwtFileName\")")

The above worked for me.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Guest
Re: new from template
« Reply #9 on: March 25, 2008, 04:02:44 PM »
...or, you could dynamically change the preferences QNEW template based upon, say, PROJECTNAME, which is what I've done in the past.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: new from template
« Reply #10 on: March 25, 2008, 04:34:55 PM »
They key is that the template must be a DWT file and either located in your specified Template locate OR the exact path included. Also, make sure your DVB with the makenewdwg Sub is loaded.

I got the same error as you when I tried to run it without having loaded the macro first.

Very bizare, as it is loaded, and the dwt is in the folder, and it is a dwt file

On a side note, TW's method worked, and I like it as Im looking for a way to not have to make a bunch of new commands for the CUI file
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

ML

  • Guest
Re: new from template
« Reply #11 on: March 31, 2008, 05:15:53 PM »

Hey CM

Yes, I was trying to figure that method out some time ago and that is correct; you would think (at first) it would be
Documents.new but it is
Documents.add as we are actually adding a new document (dwg) to the collection when we say new and choose a template.

You probably thought of this already but why not prompt the user with an inputbox:

May be I would have a variable
TempPath = "Path to dwt"

then

TempName = InputBox("Please enter a template")

Newdwg = TempPath & TempName & ".dwt"     'Not sure if you would need the extension or not.

Documents.add Newdwg

I would also consider getting rid of the path for QNEW in The File Support Paths to not cause a mix up.

M





ML

  • Guest
Re: new from template
« Reply #12 on: March 31, 2008, 05:18:03 PM »

On second thought, I would use the ".dwt" in the code, so that the user can just type the name in.

This method actually may not even be good at all because then the user needs to know the name of the templates up front.

Oh well, sorry

Mark

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: new from template
« Reply #13 on: March 31, 2008, 05:49:23 PM »
You probably thought of this already but why not prompt the user with an inputbox:
I was trying to not have the user pick anything other than the menu pulldown.  I guess I could always just send them to the folder and let them pick their dwt file from there.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

ML

  • Guest
Re: new from template
« Reply #14 on: March 31, 2008, 05:53:25 PM »

Yeah, I agree with that

Actually, just put all your Template (.dwt) files in The Template folder that ACAD is pointing too; when the user selects New, they can pick the template they want to start with. Pretty cut and dry man

It's probably not even worth automating, unless, there is absolutely a specific need.

Mark