Adding a New Layout Using a Template

Adding a New Layout Using a Template

mgorecki
Collaborator Collaborator
2,240 Views
5 Replies
Message 1 of 6

Adding a New Layout Using a Template

mgorecki
Collaborator
Collaborator
Hello,
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.
Here is a portion of my code:
'Add a layout from a template
ThisDrawing.SetVariable "SDI", 1 'Single Document Interface or MDI
Dim template_path As String 'path for templates
Dim templateName As String 'name of the template
Dim templateFileName As String 'full path and template name
template_path = "S:\templates\"

'Determine the correct template
Select Case DrawingType
Case "DrawType_1"
templateName = "Template1.dwt"
Case "DrawType_2"
templateName = "Template2.dwt"
Case "DrawType_3"
templateName = "Template3.dwt"
Case Else
templateName = "Standard.dwt"
End Select

templateFileName = template_path & templateName
ThisDrawing.New templateFileName

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?

Thanks,
Mark
0 Likes
2,241 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Hi,

A template file is a drawing file with an extension of DWT instead of
DWG. The extension is the only difference between them.

So look at the process as if the Template file were a drawing file. You
would open it, read the information about the layout and then create an
identical one in you current drawing. Then you would read the data
contained in the layout and recreate it in the current drawing. Lastly
you would close the template without saving.

All in all this is a messy process and you may find it simpler to create
a different workflow.

Things which come to mind are:
Store the characteristics of the layout in a text file and read that to
get the data you need to crate the layout in your drawing.
Make a block of the content of the layout and insert that block into you
new layout.

Lastly, with the foreseeable demise of VBA, are you sure that it is a
good use of your time to learn it in preference to a NET based language?


Regards,


Laurie Comerford

mgorecki wrote:
> Hello,
> 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.
> Here is a portion of my code:
> 'Add a layout from a template
> ThisDrawing.SetVariable "SDI", 1 'Single Document Interface or MDI
> Dim template_path As String 'path for templates
> Dim templateName As String 'name of the template
> Dim templateFileName As String 'full path and template name
> template_path = "S:\templates\"
>
> 'Determine the correct template
> Select Case DrawingType
> Case "DrawType_1"
> templateName = "Template1.dwt"
> Case "DrawType_2"
> templateName = "Template2.dwt"
> Case "DrawType_3"
> templateName = "Template3.dwt"
> Case Else
> templateName = "Standard.dwt"
> End Select
>
> templateFileName = template_path & templateName
> ThisDrawing.New templateFileName
>
> 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?
>
> Thanks,
> Mark
>
0 Likes
Message 3 of 6

mgorecki
Collaborator
Collaborator
Hi Laurie,
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. 🙂
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).

Thanks for your quick response.
0 Likes
Message 4 of 6

mgorecki
Collaborator
Collaborator
Hi Laurie,
I've bee thinking a lot about what you said regarding .NET. With VBA, I can just go to Tools > 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.
Best regards,
Mark
0 Likes
Message 5 of 6

Anonymous
Not applicable
Hi Mark,

I'm only a tyro with .NET. However, I believe the following is fairly
accurate. Where I'm wrong you can be sure that there are some posters
here who will abuse me for for misleading you, but will not provide the
correct information.

Autodesk have not yet linked .NET into AutoCAD the way they did by
linking VB6 into VBA

To code with .NET you need a separate program.
You can download the free version of the program from Microsoft, or you
can buy more sophisticated versions from Microsoft. The free version is
adequate to do all the sorts of things you are likely to need unless you
are into complex interactions with AutoCAD and it's interface. Go to
http://www.microsoft.com/express/downloads/

By the time your needs exceed the functionality of the free version you
will have enough knowledge to know why.

There is so much information on the web about programming with .NET that
you could spend the rest of your life reading it and only end up confused.

.NET programming for AutoCAD can be done in two ways (or both together -
I'm out of my depth here trying to understand the meaning of the
difference in the actual process of writing code). The first way uses
the ActiveX DLLs created for the COM (Common Object Model) world of VB,
Pascal and other similar programs. The second way uses another set of
libraries which you find information about by downloading the Autodesk
ARX Developers information.

The ActiveX files were built using "Unmanaged code" and despite the the
very clear wording in my Microsoft VB Manuals that all code written with
.NET is "Managed Code" you will find that users here refer to programs
written using ActiveX as "Unmanaged code".

If you program using the ARX based stuff, then your program will be said
to be "Managed code"

In general this Managed code is harder to learn and write - particularly
if you are familiar with the Object models in the ActiveX DLLs.

The processes to add a library to your program are the same with the
exception that as you load them they are listed under different tabs in
the dialog box. You get intellisense either way.

To write your program, it is easiest to start by using an existing
program supplied by Autodesk and modify it as the necessary libraries
will be in place and you will find code like:

{code}
Imports LibraryName
{code}

I have yet to find an elegant way of knowing what you should add - or
not add when using this "Imports" process, whereas if you start with an
existing program, the writer has probably sorted that out for you.

To test the program you compile it to a DLL, then use the AutoCAD
NETLOAD command to load the DLL. Within the DLL you will have defined
an AutoCAD command and you simply run the command from a menu, or
keyboard etc. etc.

There is no NETUNLOAD command, so that during the debugging phase, you
have to keep stopping and restarting AutoCAD which is very inconvenient.

Lastly, although it is regularly abused here for occasional inaccuracies
and now version outdated, you will find "VB.NET Programming for AutoCAD
Customisation" by Jerry Winters very helpful in getting started and
expanding on what I've posted. At this stage I'm only starting into the
book and in a year or so when I finish it, I'll be better informed.


Regards,


Laurie Comerford




mgorecki wrote:
> Hi Laurie,
> I've bee thinking a lot about what you said regarding .NET. With VBA, I can just go to Tools > 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.
> Best regards,
> Mark
>
0 Likes
Message 6 of 6

mgorecki
Collaborator
Collaborator
Hi Laurie,
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.

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.

Have a great day,
Mark
0 Likes