<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Adding a New Layout Using a Template in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/adding-a-new-layout-using-a-template/m-p/2657831#M13835</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
A template file is a drawing file with an extension of DWT instead of &lt;BR /&gt;
DWG.  The extension is the only difference between them.&lt;BR /&gt;
&lt;BR /&gt;
So look at the process as if the Template file were a drawing file.  You &lt;BR /&gt;
would open it, read the information about the layout and then create an &lt;BR /&gt;
identical one in you current drawing.  Then you would read the data &lt;BR /&gt;
contained in the layout and recreate it in the current drawing. Lastly &lt;BR /&gt;
you would close the template without saving.&lt;BR /&gt;
&lt;BR /&gt;
All in all this is a messy process and you may find it simpler to create &lt;BR /&gt;
a different workflow.&lt;BR /&gt;
&lt;BR /&gt;
Things which come to mind are:&lt;BR /&gt;
Store the characteristics of the layout in a text file and read that to &lt;BR /&gt;
get the data you need to crate the layout in your drawing.&lt;BR /&gt;
Make a block of the content of the layout and insert that block into you &lt;BR /&gt;
new layout.&lt;BR /&gt;
&lt;BR /&gt;
Lastly, with the foreseeable demise of VBA, are you sure that it is a &lt;BR /&gt;
good use of your time to learn it in preference to a NET based language?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Laurie Comerford&lt;BR /&gt;
&lt;BR /&gt;
mgorecki wrote:&lt;BR /&gt;
&amp;gt; Hello,&lt;BR /&gt;
&amp;gt; I'm fairly new to VBA and learning from code I read from books and online.  What I need to do is create a function that will createa new layout tab from a template file on the network.  I have seen some code, but they are using the template name and that's about it (from what I can tell).  I have templates that have multiple layouts in them.  So what I need to do is input a specific layout tab from the template as the new layout template in my drawing.&lt;BR /&gt;
&amp;gt; Here is a portion of my code:&lt;BR /&gt;
&amp;gt; 'Add a layout from a template&lt;BR /&gt;
&amp;gt;         ThisDrawing.SetVariable "SDI", 1  'Single Document Interface or MDI&lt;BR /&gt;
&amp;gt;         Dim template_path As String     'path for templates&lt;BR /&gt;
&amp;gt;         Dim templateName As String      'name of the template&lt;BR /&gt;
&amp;gt;         Dim templateFileName As String  'full path and template name&lt;BR /&gt;
&amp;gt;         template_path = "S:\templates\"&lt;BR /&gt;
&amp;gt;     &lt;BR /&gt;
&amp;gt; 'Determine the correct template&lt;BR /&gt;
&amp;gt;         Select Case DrawingType&lt;BR /&gt;
&amp;gt;             Case "DrawType_1"&lt;BR /&gt;
&amp;gt;                 templateName = "Template1.dwt"&lt;BR /&gt;
&amp;gt;             Case "DrawType_2"&lt;BR /&gt;
&amp;gt;                 templateName = "Template2.dwt"&lt;BR /&gt;
&amp;gt;             Case "DrawType_3"&lt;BR /&gt;
&amp;gt;                 templateName = "Template3.dwt"&lt;BR /&gt;
&amp;gt;             Case Else&lt;BR /&gt;
&amp;gt;                 templateName = "Standard.dwt"&lt;BR /&gt;
&amp;gt;         End Select&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;         templateFileName = template_path &amp;amp; templateName&lt;BR /&gt;
&amp;gt;         ThisDrawing.New templateFileName&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; So, for example, Template2.dwt has 3 layouts (T1, T2, T3).  What is the command to insert the third layout from the template into my drawing as a new layout?&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Thanks,&lt;BR /&gt;
&amp;gt; Mark&lt;BR /&gt;
&amp;gt;</description>
    <pubDate>Tue, 30 Mar 2010 21:20:52 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2010-03-30T21:20:52Z</dc:date>
    <item>
      <title>Adding a New Layout Using a Template</title>
      <link>https://forums.autodesk.com/t5/vba-forum/adding-a-new-layout-using-a-template/m-p/2657830#M13834</link>
      <description>Hello,&lt;BR /&gt;
I'm fairly new to VBA and learning from code I read from books and online.  What I need to do is create a function that will createa new layout tab from a template file on the network.  I have seen some code, but they are using the template name and that's about it (from what I can tell).  I have templates that have multiple layouts in them.  So what I need to do is input a specific layout tab from the template as the new layout template in my drawing.&lt;BR /&gt;
Here is a portion of my code:&lt;BR /&gt;
'Add a layout from a template&lt;BR /&gt;
        ThisDrawing.SetVariable "SDI", 1  'Single Document Interface or MDI&lt;BR /&gt;
        Dim template_path As String     'path for templates&lt;BR /&gt;
        Dim templateName As String      'name of the template&lt;BR /&gt;
        Dim templateFileName As String  'full path and template name&lt;BR /&gt;
        template_path = "S:\templates\"&lt;BR /&gt;
    &lt;BR /&gt;
'Determine the correct template&lt;BR /&gt;
        Select Case DrawingType&lt;BR /&gt;
            Case "DrawType_1"&lt;BR /&gt;
                templateName = "Template1.dwt"&lt;BR /&gt;
            Case "DrawType_2"&lt;BR /&gt;
                templateName = "Template2.dwt"&lt;BR /&gt;
            Case "DrawType_3"&lt;BR /&gt;
                templateName = "Template3.dwt"&lt;BR /&gt;
            Case Else&lt;BR /&gt;
                templateName = "Standard.dwt"&lt;BR /&gt;
        End Select&lt;BR /&gt;
&lt;BR /&gt;
        templateFileName = template_path &amp;amp; templateName&lt;BR /&gt;
        ThisDrawing.New templateFileName&lt;BR /&gt;
&lt;BR /&gt;
So, for example, Template2.dwt has 3 layouts (T1, T2, T3).  What is the command to insert the third layout from the template into my drawing as a new layout?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Mark</description>
      <pubDate>Tue, 30 Mar 2010 20:30:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/adding-a-new-layout-using-a-template/m-p/2657830#M13834</guid>
      <dc:creator>mgorecki</dc:creator>
      <dc:date>2010-03-30T20:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a New Layout Using a Template</title>
      <link>https://forums.autodesk.com/t5/vba-forum/adding-a-new-layout-using-a-template/m-p/2657831#M13835</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
A template file is a drawing file with an extension of DWT instead of &lt;BR /&gt;
DWG.  The extension is the only difference between them.&lt;BR /&gt;
&lt;BR /&gt;
So look at the process as if the Template file were a drawing file.  You &lt;BR /&gt;
would open it, read the information about the layout and then create an &lt;BR /&gt;
identical one in you current drawing.  Then you would read the data &lt;BR /&gt;
contained in the layout and recreate it in the current drawing. Lastly &lt;BR /&gt;
you would close the template without saving.&lt;BR /&gt;
&lt;BR /&gt;
All in all this is a messy process and you may find it simpler to create &lt;BR /&gt;
a different workflow.&lt;BR /&gt;
&lt;BR /&gt;
Things which come to mind are:&lt;BR /&gt;
Store the characteristics of the layout in a text file and read that to &lt;BR /&gt;
get the data you need to crate the layout in your drawing.&lt;BR /&gt;
Make a block of the content of the layout and insert that block into you &lt;BR /&gt;
new layout.&lt;BR /&gt;
&lt;BR /&gt;
Lastly, with the foreseeable demise of VBA, are you sure that it is a &lt;BR /&gt;
good use of your time to learn it in preference to a NET based language?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Laurie Comerford&lt;BR /&gt;
&lt;BR /&gt;
mgorecki wrote:&lt;BR /&gt;
&amp;gt; Hello,&lt;BR /&gt;
&amp;gt; I'm fairly new to VBA and learning from code I read from books and online.  What I need to do is create a function that will createa new layout tab from a template file on the network.  I have seen some code, but they are using the template name and that's about it (from what I can tell).  I have templates that have multiple layouts in them.  So what I need to do is input a specific layout tab from the template as the new layout template in my drawing.&lt;BR /&gt;
&amp;gt; Here is a portion of my code:&lt;BR /&gt;
&amp;gt; 'Add a layout from a template&lt;BR /&gt;
&amp;gt;         ThisDrawing.SetVariable "SDI", 1  'Single Document Interface or MDI&lt;BR /&gt;
&amp;gt;         Dim template_path As String     'path for templates&lt;BR /&gt;
&amp;gt;         Dim templateName As String      'name of the template&lt;BR /&gt;
&amp;gt;         Dim templateFileName As String  'full path and template name&lt;BR /&gt;
&amp;gt;         template_path = "S:\templates\"&lt;BR /&gt;
&amp;gt;     &lt;BR /&gt;
&amp;gt; 'Determine the correct template&lt;BR /&gt;
&amp;gt;         Select Case DrawingType&lt;BR /&gt;
&amp;gt;             Case "DrawType_1"&lt;BR /&gt;
&amp;gt;                 templateName = "Template1.dwt"&lt;BR /&gt;
&amp;gt;             Case "DrawType_2"&lt;BR /&gt;
&amp;gt;                 templateName = "Template2.dwt"&lt;BR /&gt;
&amp;gt;             Case "DrawType_3"&lt;BR /&gt;
&amp;gt;                 templateName = "Template3.dwt"&lt;BR /&gt;
&amp;gt;             Case Else&lt;BR /&gt;
&amp;gt;                 templateName = "Standard.dwt"&lt;BR /&gt;
&amp;gt;         End Select&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;         templateFileName = template_path &amp;amp; templateName&lt;BR /&gt;
&amp;gt;         ThisDrawing.New templateFileName&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; So, for example, Template2.dwt has 3 layouts (T1, T2, T3).  What is the command to insert the third layout from the template into my drawing as a new layout?&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Thanks,&lt;BR /&gt;
&amp;gt; Mark&lt;BR /&gt;
&amp;gt;</description>
      <pubDate>Tue, 30 Mar 2010 21:20:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/adding-a-new-layout-using-a-template/m-p/2657831#M13835</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-03-30T21:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a New Layout Using a Template</title>
      <link>https://forums.autodesk.com/t5/vba-forum/adding-a-new-layout-using-a-template/m-p/2657832#M13836</link>
      <description>Hi Laurie,&lt;BR /&gt;
Thanks for the info.  Yes I would rather be using/learning .NET, but I've already started this code in VBA and just wanted to get it done. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
I guess if it's a real hassle to be able to select a particular layout from a particular dwt, I could copy one of the existing layouts and just have the code make the needed changes to the new layout copy.  I was just hoping it would be a simple command like "ThisDrawing.New templatefilename(layout name to be read in).&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your quick response.</description>
      <pubDate>Tue, 30 Mar 2010 21:29:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/adding-a-new-layout-using-a-template/m-p/2657832#M13836</guid>
      <dc:creator>mgorecki</dc:creator>
      <dc:date>2010-03-30T21:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a New Layout Using a Template</title>
      <link>https://forums.autodesk.com/t5/vba-forum/adding-a-new-layout-using-a-template/m-p/2657833#M13837</link>
      <description>Hi Laurie,&lt;BR /&gt;
I've bee thinking a lot about what you said regarding .NET.  With VBA, I can just go to Tools &amp;gt; Macro and get started, but how would I do that with VB .NET?  VBA works inside of AutoCad, how does .NET interact?  Thanks for any info to help this newbie out.&lt;BR /&gt;
Best regards,&lt;BR /&gt;
Mark</description>
      <pubDate>Tue, 06 Apr 2010 15:34:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/adding-a-new-layout-using-a-template/m-p/2657833#M13837</guid>
      <dc:creator>mgorecki</dc:creator>
      <dc:date>2010-04-06T15:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a New Layout Using a Template</title>
      <link>https://forums.autodesk.com/t5/vba-forum/adding-a-new-layout-using-a-template/m-p/2657834#M13838</link>
      <description>Hi Mark,&lt;BR /&gt;
&lt;BR /&gt;
I'm only a tyro with .NET.  However, I believe the following is fairly &lt;BR /&gt;
accurate.  Where I'm wrong you can be sure that there are some posters &lt;BR /&gt;
here who will abuse me for for misleading you, but will not provide the &lt;BR /&gt;
correct information.&lt;BR /&gt;
&lt;BR /&gt;
Autodesk have not yet linked .NET into AutoCAD the way they did by &lt;BR /&gt;
linking VB6 into VBA&lt;BR /&gt;
&lt;BR /&gt;
To code with .NET you need a separate program.&lt;BR /&gt;
You can download the free version of the program from Microsoft, or you &lt;BR /&gt;
can buy more sophisticated versions from Microsoft.  The free version is &lt;BR /&gt;
adequate to do all the sorts of things you are likely to need unless you &lt;BR /&gt;
are into complex interactions with AutoCAD and it's interface.  Go to &lt;BR /&gt;
http://www.microsoft.com/express/downloads/&lt;BR /&gt;
&lt;BR /&gt;
By the time your needs exceed the functionality of the free version you &lt;BR /&gt;
will have enough knowledge to know why.&lt;BR /&gt;
&lt;BR /&gt;
There is so much information on the web about programming with .NET that &lt;BR /&gt;
you could spend the rest of your life reading it and only end up confused.&lt;BR /&gt;
&lt;BR /&gt;
.NET programming for AutoCAD can be done in two ways (or both together - &lt;BR /&gt;
I'm out of my depth here trying to understand the meaning of the &lt;BR /&gt;
difference in the actual process of writing code).  The first way uses &lt;BR /&gt;
the ActiveX DLLs created for the COM (Common Object Model) world of VB, &lt;BR /&gt;
Pascal and other similar programs.  The second way uses another set of &lt;BR /&gt;
libraries which you find information about by downloading the Autodesk &lt;BR /&gt;
ARX Developers information. &lt;BR /&gt;
&lt;BR /&gt;
The ActiveX files were built using "Unmanaged code" and despite the the &lt;BR /&gt;
very clear wording in my Microsoft VB Manuals that all code written with &lt;BR /&gt;
.NET is "Managed Code" you will find that users here refer to programs &lt;BR /&gt;
written using ActiveX as "Unmanaged code".&lt;BR /&gt;
&lt;BR /&gt;
If you program using the ARX based stuff, then your program will be said &lt;BR /&gt;
to be "Managed code" &lt;BR /&gt;
&lt;BR /&gt;
In general this Managed code is harder to learn and write - particularly &lt;BR /&gt;
if you are familiar with the Object models in the ActiveX DLLs.&lt;BR /&gt;
&lt;BR /&gt;
The processes to add a library to your program are the same with the &lt;BR /&gt;
exception that as you load them they are listed under different tabs in &lt;BR /&gt;
the dialog box.  You get intellisense either way.&lt;BR /&gt;
&lt;BR /&gt;
To write your program, it is easiest to start by using an existing &lt;BR /&gt;
program supplied by Autodesk and modify it as the necessary libraries &lt;BR /&gt;
will be in place and you will find code like:&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
Imports LibraryName&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
I have yet to find an elegant way of knowing what you should add - or &lt;BR /&gt;
not add when using this "Imports" process, whereas if you start with an &lt;BR /&gt;
existing program, the writer has probably sorted that out for you.&lt;BR /&gt;
&lt;BR /&gt;
To test the program you compile it to a DLL, then use the AutoCAD &lt;BR /&gt;
NETLOAD command to load the DLL.  Within the DLL you will have defined &lt;BR /&gt;
an AutoCAD command and you simply run the command from a menu, or &lt;BR /&gt;
keyboard etc. etc.&lt;BR /&gt;
&lt;BR /&gt;
There is no NETUNLOAD command, so that during the debugging phase, you &lt;BR /&gt;
have to keep stopping and restarting AutoCAD which is very inconvenient.&lt;BR /&gt;
&lt;BR /&gt;
Lastly, although it is regularly abused here for occasional inaccuracies &lt;BR /&gt;
and now version outdated, you will find "VB.NET Programming for AutoCAD &lt;BR /&gt;
Customisation" by Jerry Winters very helpful in getting started and &lt;BR /&gt;
expanding on what I've posted.  At this stage I'm only starting into the &lt;BR /&gt;
book and in a year or so when I finish it, I'll be better informed.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Laurie Comerford&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
mgorecki wrote:&lt;BR /&gt;
&amp;gt; Hi Laurie,&lt;BR /&gt;
&amp;gt; I've bee thinking a lot about what you said regarding .NET.  With VBA, I can just go to Tools &amp;gt; Macro and get started, but how would I do that with VB .NET?  VBA works inside of AutoCad, how does .NET interact?  Thanks for any info to help this newbie out.&lt;BR /&gt;
&amp;gt; Best regards,&lt;BR /&gt;
&amp;gt; Mark&lt;BR /&gt;
&amp;gt;</description>
      <pubDate>Tue, 06 Apr 2010 22:31:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/adding-a-new-layout-using-a-template/m-p/2657834#M13838</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-04-06T22:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a New Layout Using a Template</title>
      <link>https://forums.autodesk.com/t5/vba-forum/adding-a-new-layout-using-a-template/m-p/2657835#M13839</link>
      <description>Hi Laurie,&lt;BR /&gt;
As always, thank you for your quick and informative response.  I usually ignore naysayers if they have nothing to back up their position, besides you have been very helpful to me on other occasions and I appreciate that.&lt;BR /&gt;
&lt;BR /&gt;
I've been looking into VB .NET programming tutorials like http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html.  But I will also try to get a hold of the book you mentioned.&lt;BR /&gt;
&lt;BR /&gt;
Have a great day,&lt;BR /&gt;
Mark</description>
      <pubDate>Tue, 06 Apr 2010 22:47:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/adding-a-new-layout-using-a-template/m-p/2657835#M13839</guid>
      <dc:creator>mgorecki</dc:creator>
      <dc:date>2010-04-06T22:47:04Z</dc:date>
    </item>
  </channel>
</rss>

