Jump to content

Batch Script / VBA - 512 Drawings


kurlytoenail

Recommended Posts

Hi guys, first of all thanks for taking the time to ready my post. Life is busy but so many people out there make a real effort to help other people and I really appreciate it.

 

Secondly, I've got what seems like a huge challenge to overcome. I am not proficient with script files or vba or any type of programming for that matter. I am merely an engineer in need of some stellar assistance.

 

I have in my possession 512 client autocad drawings (ver.2008) that require some manipulation (details to follow) to prepare the drawings for a substantial control system migration. Thankfully the preparation works that are required are fairly typical across the full suite of drawings. The preparation scope includes, but not limited to, scaling the full contents of the drawing in model space to fit snugly into an A2 drawing border, deleting the existing drawing border and inserting a new drawing border.

 

My first question is this. How do I execute this scope of preparation works in the most time efficient manner? The process doesn't have to be pretty and I just want the 512 processed drawings at the end of the day (not literally!)

 

Any pointers would be greatly appreciated. I've attached an example of the client drawing and also the new drawing border for information.

 

Thanks in advance.

 

A2_Border.dwg

Test_Loop.dwg

Link to comment
Share on other sites

It might have been nice if the client's title block and border was a single attributed block that could be easily erased and replaced. It doesn't appear to be so.

 

The client's drawing was done in imperial units and you want to convert everything over to metric units? Have you already worked out the scale factor?

 

So everything will be in model space and you will not be using a layout for your new title block and border. Correct?

Link to comment
Share on other sites

It will depend on what you mean by scaling to fit A2, does it have to be a standard recognisable scale or is scale to fit sufficient, I would personally create a layout with the A2 template and include a viewport, then for each drawing delete the old title block (leaving the old border if it nicely outlines all the drawings), this is easy to do if the layouts are all the same but painful if everything isn't standardised, then import the new layout and zoom extents in the viewport. Then onto the next drawing, it could be a matter of hours or a really painfully slow boring job if all the drawings are laid out differently, and if everything is laid out like the example then a script would be ideal.

Link to comment
Share on other sites

You need to provide a true sample dwg I know about copyright but create a random dwg some plines that represent the bounds of the actual model space dwg but still in feet. The obvious here is to use layouts with the new A2 title block rather than in model. Need a title block that matches the model space objects like Remark the sample its a block at scale of 1 which is not really correct for what you are describing.

 

Its possible to find the approx center of the objects and do a metric to feet type scale factor and make a A2.

 

The 512 scripting part sounds like the easy bit.

 

Ps Steven-g join the dark side and have a go at lisp.

Link to comment
Share on other sites

@ BIGAL

Never, I'm tinkering with VBA, but this dog is just too old to play with lisp, people like yourself are just too good at it, besides there is that much material available here and other forums that the ability to perform internet searches would find most solutions quicker than trying to learn a new language

Link to comment
Share on other sites

@Remark I'm not sure that the imperial thing is an issue (or is it?). If it's something that can be incorporated easily into a script then I guess it would be a bonus?

 

I did consider the layout in paper space but the client cad procedures (LOL) state that the text height must be 2.5mm minimum.

 

A few things I have figured out so far which may or may not be useful...

 

Scale factor = 33

Global text style change to 'Standard' (client stipulation)

Global text height change to 2.5mm (client stipulation)

 

Plus a bit of manipulation to get the position right gives me the attached drawing which is very close to what I need (see attached)

 

Test_Output.dwg

Link to comment
Share on other sites

Is it worthwhile developing a script file or similar to execute the scope detailed above OR should we entertain the manual manipulation route for each individual drawing?

Link to comment
Share on other sites

Text in a layout can be 2.5mm !! Set your paper in the layout as A2. Put the border on the layout. Create a viewport that is as big as possible inside the border. Save it as a template. Then all you need do is open every file insert a new layout from your template. delete or turn off the border in ModelSpace. And in the new layout either zoom extents in the viewport, or if the scale is important then zoom with a scale factor. Save the drawing move onto the next. With a macro that should take only a couple of hours tops and with a script probably only minutes, obviously, that doesn't include doing the preparation and writing/testing of a script or macro. And it also won't make allowances for the odd drawing that for some reason fails the logic of this approach. Only you can judge whether that is going to save you time on this project and how confident you are writing the code, only you have seen how the other drawings may be different.

Link to comment
Share on other sites

Having a look at the dwg this will automate the new title block into a layout using a adjusted fit to the A2 sheet size. I do need some help error trapping the "xref is missing" but it appears to be a logo so should work. Have a look at text size .

 

There is no error about if all dwg's are the same so test on a few at a time. I can give you a few hints about writing the script also.

 

; Fit model space to a fixed size title block in a layout
; By Alan H Aug 2017

(vl-load-com)
(defun c:ktnl ( / ss lay alllayouts)
(setvar "ctab" "Model")

(command "erase" (ssget "x" (list (cons 0 "insert")(cons 2 "JE_BORDER")(cons 410 "Model")))  "")

(setq alllayouts (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))))
(vlax-for lay alllayouts
(if (= 1 (vla-get-taborder lay))
(setvar "ctab" (vla-get-name lay))
)
)

(command "erase" (ssget "x" (list (cons 0 "Viewport"))) "") 

(setvar "attdia" 0)
(command "insert" "JE_BORDER" (list 0 0) 1 1 0 "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "")

(command "-layer" "M" "Vport" "")
(command "mview" (list 7.75 42.0) (list 576.5 405.5))
(setq obj (vlax-ename->vla-object (entlast)))
(command "zoom" "E")

(command "mspace")
(command "zoom" "E")
(command "zoom" 0.95x)
(setq sc (vla-get-customscale obj))
(vla-put-DisplayLocked  obj -1)

(setq ss (ssget "X" (list (cons 0 "Text"))))
(repeat (setq x (sslength ss))
(setq tobj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(vla-put-height tobj(/ (vla-get-height tobj) sc))

)
(command "pspace")
(command "zoom" "E")
)
(c:ktnl)

script if no xrefs

Open dwg1 (load "kntl") close "y")
Open dwg2 (load "kntl") close "y")
Open dwg3 (load "kntl") close "y")

Edited by BIGAL
Link to comment
Share on other sites

@BIGAL

 

Thanks for your response. Apologies, prior to this little adventure I've had very minimal experience of macros/lisp etc and I'm reading 3 separate Autolisp guides concurrently to bring me up to speed.

 

I punched in your code to 'Autolisp -> Visual Lisp Editor' and got the following...

 

C:KTNL

; error: no function definition: VLAX-GET-ACAD-OBJECT

_$

_$

Link to comment
Share on other sites

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...