Jump to content
Fett2oo5

Automation for multiple details in viewports

Recommended Posts

Fett2oo5

I could use some insight from some clever people.....

Sorry for the length of the post, but I feel more explanation will help you in understanding my situation. I also believe this is a situation that MANY designers/Engineers face. I have tried to be as concise and brief as possible.

 

We do custom fabrication of steel structures. We have a "bread-n-butter" product, as well as accommodating many different custom steel projects. Quite often these structures need many "small", and widely different parts. Therefore, for each project the fabricators need: part dwgs / details / subassembly details / etc..

 

(Just to be absolutely clear...)

Definition of terms:

Part: A piece of steel to be welded to another piece of steel, to create an over all assembly.

Detail: A zoomed in or additional notes/dimensions provided of a particular joint of a steel part to another steel part.

 

Evolution of the process over the past year:

Previously we have used a single .dwg file for each and every part/detail. I've introduced having all parts/details for the project in one .dwg file. And have them shown in viewports in a layout tab with a titleblock. I'd like to automate as much of this process as I can. (The process is up for review if you wish to offer alternatives.)

 

Using AutoCAD 2013.

Process:

MODELSPACE:

The overall design of the project is completed.

Any/all parts, steel joint details, fabrication details, sub-assembly details are created in the same .dwg file.

LAYOUT TAB / PAPERSPACE:

We would like to have as many parts/details on one printed sheet as possible.

A company title block is in the layout tab.

Multiple viewports are created in paperspace (as many as needed to show all the parts/details).

Each viewport would show one of the parts/details from modelspace.

 

Pictures worth their memory size:

xzEFzN8.png----WZfSLN5.png----fLaAbAi.png----

 

usbRrfT.png

khLO8uH.png

 

Link to all the above images on Imgur.com

 

LISP routine explained in reply

 

*Edit* Added example .dwg file: View Parts in Layout.dwg

Edited by Fett2oo5
Marked as solved

Share this post


Link to post
Share on other sites
Fett2oo5

The code for the LISP referenced in the original post:

 

I genuinely do not remember where I got this, and I have to admit this particular code is above my understanding, as I have not made it to using vla*.

To be honest with you, I was hoping there was a simpler way to write this.

;;; BoxObj will ask the user to select objects,
;;;   then will draw a rectangle around the selected objects.
(defun c:BoxObj (/ ss obj ss doc Mi Ma pts)
 (vl-load-com)
 (if (setq ss (ssget))
   (progn
     (vlax-for obj (setq ss (vla-get-ActiveSelectionSet
                              (setq doc (vla-get-ActiveDocument
                                          (vlax-get-acad-object)))))
       (vla-getBoundingbox obj 'Mi 'Ma)
       (setq pts (cons (vlax-safearray->list Mi)
                       (cons (vlax-safearray->list Ma) pts))))
     (vla-delete ss)
     (setq Mi (apply (function mapcar) (cons 'min pts))
           Ma (apply (function mapcar) (cons 'max pts)))
     (vla-put-closed
       (vla-addLightWeightPolyline
         (if (zerop (vla-get-ActiveSpace doc))
           (if (eq :vlax-true (vla-get-mspace doc))
             (vla-get-ModelSpace doc)
             (vla-get-PaperSpace doc))
           (vla-get-ModelSpace doc))
         (variant (vlax-safearray-fill (safearray vlax-vbDouble '(0 . 7))
                    (list (car Mi) (cadr Mi) (car Mi) (cadr Ma)
                          (car Ma) (cadr Ma) (car Ma) (cadr Mi))))) :vlax-true)))
 (princ))

 

Purpose:

Ideally the task I would like to be performed is:

To ask the user for the objects to be contained in the rectangle

Ask the user how much of an offset, from the selected objects, they would like to rectangle to be

The rectangle to be on the defpoints layer.

 

ANY help on this is greatly appreciated. I'd like to have a solution (obviously) but it's even more important for me to understand how it works.

 

I'm excited to learn about how to create a solution which is why I have put so much detail and effort into explaining it to you.

Share this post


Link to post
Share on other sites
Lee Mac

This will performs Steps 1-4:

([color=BLUE]defun[/color] c:bbx ( [color=BLUE]/[/color] box off sel tmp )
   ([color=BLUE]if[/color]
       ([color=BLUE]not[/color]
           ([color=BLUE]and[/color]
               ([color=BLUE]setq[/color] off ([color=BLUE]getenv[/color] [color=MAROON]"LMac\\bbx-off"[/color]))
               ([color=BLUE]setq[/color] off ([color=BLUE]distof[/color] off 2))
           )
       )
       ([color=BLUE]setq[/color] off ([color=BLUE]atof[/color] ([color=BLUE]setenv[/color] [color=MAROON]"LMac\\bbx-off"[/color] [color=MAROON]"0.75"[/color])))
   )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] tmp ([color=BLUE]getdist[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nSpecify offset <"[/color] ([color=BLUE]rtos[/color] off) [color=MAROON]">: "[/color])))
       ([color=BLUE]setenv[/color] [color=MAROON]"LMac\\bbx-off"[/color] ([color=BLUE]rtos[/color] ([color=BLUE]setq[/color] off tmp) 2))
   )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] sel ([color=BLUE]ssget[/color]))
       ([color=BLUE]if[/color] ([color=BLUE]setq[/color] box (LM:ssboundingbox sel)
                 box ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( a b ) ([color=BLUE]mapcar[/color] a b ([color=BLUE]list[/color] off off))) '([color=BLUE]-[/color] [color=BLUE]+[/color]) box)
           )
           ([color=BLUE]entmake[/color]
               ([color=BLUE]append[/color]
                  '(   (000 . [color=MAROON]"LWPOLYLINE"[/color])
                       (100 . [color=MAROON]"AcDbEntity"[/color])
                       (100 . [color=MAROON]"AcDbPolyline"[/color])
                       (008 . [color=MAROON]"Defpoints"[/color])
                       (090 . 4)
                       (070 . 1)
                   )
                   ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]cons[/color] 10 ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( y ) (([color=BLUE]eval[/color] y) box)) x)))
                      '(
                           ([color=BLUE]caar[/color]   [color=BLUE]cadar[/color])
                           ([color=BLUE]caadr[/color]  [color=BLUE]cadar[/color])
                           ([color=BLUE]caadr[/color] [color=BLUE]cadadr[/color])
                           ([color=BLUE]caar[/color]  [color=BLUE]cadadr[/color])
                       )
                   )
               )
           )
       )
   )
   ([color=BLUE]princ[/color])
)

[color=GREEN];; Selection Set Bounding Box  -  Lee Mac[/color]
[color=GREEN];; Returns a list of the lower-left and upper-right WCS coordinates of a[/color]
[color=GREEN];; rectangular frame bounding all objects in a supplied selection set.[/color]
[color=GREEN];; s - [sel] Selection set for which to return bounding box[/color]

([color=BLUE]defun[/color] LM:ssboundingbox ( s [color=BLUE]/[/color] a b i m n o )
   ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] i ([color=BLUE]sslength[/color] s))
       ([color=BLUE]if[/color]
           ([color=BLUE]and[/color]
               ([color=BLUE]setq[/color] o ([color=BLUE]vlax-ename->vla-object[/color] ([color=BLUE]ssname[/color] s ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] i)))))
               ([color=BLUE]vlax-method-applicable-p[/color] o 'getboundingbox)
               ([color=BLUE]not[/color] ([color=BLUE]vl-catch-all-error-p[/color] ([color=BLUE]vl-catch-all-apply[/color] '[color=BLUE]vla-getboundingbox[/color] ([color=BLUE]list[/color] o 'a 'b))))
           )
           ([color=BLUE]setq[/color] m ([color=BLUE]cons[/color] ([color=BLUE]vlax-safearray->list[/color] a) m)
                 n ([color=BLUE]cons[/color] ([color=BLUE]vlax-safearray->list[/color] b) n)
           )
       )
   )
   ([color=BLUE]if[/color] ([color=BLUE]and[/color] m n)
       ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( a b ) ([color=BLUE]apply[/color] '[color=BLUE]mapcar[/color] ([color=BLUE]cons[/color] a b))) '([color=BLUE]min[/color] [color=BLUE]max[/color]) ([color=BLUE]list[/color] m n))
   )
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

Share this post


Link to post
Share on other sites
Fett2oo5

WOW Lee! You never cease to amaze. This time with your speed.

 

Thank you!

 

I'd seen your SSBoundingBox on your site before; I knew how to ask the user for selection and offset, but being unfamiliar with vla* I was trying to incorporate it into your SSBB lines but was doing it all wrong.

 

From your example, it's best to separate the two "tasks"? Is that because you had an existing BoundBox code?

 

What I really like about your solution is how easily I can read it, almost like a book.

 

I'm going to do some research into the commands you are using in the BoundingBox section. So much still to learn.

Share this post


Link to post
Share on other sites
Lee Mac
WOW Lee! You never cease to amaze. This time with your speed.

 

Thank you!

 

You're welcome - and thank you for your kind compliments!

 

I'd seen your SSBoundingBox on your site before; I knew how to ask the user for selection and offset, but being unfamiliar with vla* I was trying to incorporate it into your SSBB lines but was doing it all wrong.

 

From your example, it's best to separate the two "tasks"? Is that because you had an existing BoundBox code?

 

Functions such as those found in the 'Subfunction Library' section of my site are intended to be library functions (that is, extensions to the standard AutoLISP functions), and should therefore be evaluated from within other programs without modifying the source code of the library function.

 

Such functions may then support several programs without the need to repeatedly rewrite code and effectively reinvent the wheel for every program. The library functions tend to be written to be as efficient & robust as possible so that one need not be concerned with the inner-workings of the subfunction, but can be confident that upon evaluating the subfunction with appropriate arguments, that the function will perform a given operation and return a given value - just as you might expect with the standard AutoLISP functions.

 

Back to the task at hand - the below code will perform Step 5:

([color=BLUE]defun[/color] c:cvp ( [color=BLUE]/[/color] ent enx lst )
   ([color=BLUE]cond[/color]
       (   ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'tilemode))
           ([color=BLUE]princ[/color] [color=MAROON]"\nCommand not allowed in Modelspace."[/color])
       )
       (   ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'cvport))
           ([color=BLUE]princ[/color] [color=MAROON]"\nPlease activate a viewport."[/color])
       )
       (   ([color=BLUE]while[/color]
               ([color=BLUE]progn[/color] ([color=BLUE]setvar[/color] 'errno 0) ([color=BLUE]setq[/color] ent ([color=BLUE]car[/color] ([color=BLUE]entsel[/color] [color=MAROON]"\nSelect polyline frame: "[/color])))
                   ([color=BLUE]cond[/color]
                       (   ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'errno))
                           ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color])
                       )
                       (   ([color=BLUE]null[/color] ent) [color=BLUE]nil[/color])
                       (   ([color=BLUE]/=[/color] [color=MAROON]"LWPOLYLINE"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]setq[/color] enx ([color=BLUE]entget[/color] ent)))))
                           ([color=BLUE]princ[/color] [color=MAROON]"\nThe selected object is not a polyline."[/color])
                       )
                       (   ([color=BLUE]setq[/color] lst ([color=BLUE]mapcar[/color] '[color=BLUE]cdr[/color] ([color=BLUE]vl-remove-if-not[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]=[/color] 10 ([color=BLUE]car[/color] x))) enx)))
                           ([color=BLUE]vla-zoomwindow[/color] (LM:acapp)
                               ([color=BLUE]vlax-3D-point[/color] ([color=BLUE]apply[/color] '[color=BLUE]mapcar[/color] ([color=BLUE]cons[/color] '[color=BLUE]min[/color] lst)))
                               ([color=BLUE]vlax-3D-point[/color] ([color=BLUE]apply[/color] '[color=BLUE]mapcar[/color] ([color=BLUE]cons[/color] '[color=BLUE]max[/color] lst)))
                           )
                           ([color=BLUE]vla-put-mspace[/color] ([color=BLUE]vla-get-activedocument[/color] (LM:acapp)) [color=BLUE]:vlax-false[/color])
                       )
                   )
               )
           )
       )
   )
   ([color=BLUE]princ[/color])
)

[color=GREEN];; Application Object  -  Lee Mac[/color]
[color=GREEN];; Returns the VLA Application Object[/color]

([color=BLUE]defun[/color] LM:acapp [color=BLUE]nil[/color]
   ([color=BLUE]eval[/color] ([color=BLUE]list[/color] '[color=BLUE]defun[/color] 'LM:acapp '[color=BLUE]nil[/color] ([color=BLUE]vlax-get-acad-object[/color])))
   (LM:acapp)
)
   
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

Share this post


Link to post
Share on other sites
Fett2oo5

Thank you Lee, I've learned quite a lot from this thread.

I spent some time last week going through your examples, and some of my old lisps. I would piece them together but not mix them, keeping them separate as you stated.

This is more like my Excel Macros; for whatever reason I thought it was best to have (any given lisps routine) encompass the entire task.

Thankfully I haven't created too many large routines and don't need to rewrite but a few. This has forced me to rethink my strategy for the LISPS I have planned in the next few months.

 

So, I sincerely thank you.

Share this post


Link to post
Share on other sites
Lee Mac

That's great to hear, you're entirely welcome - I'm glad that you could benefit from the thread.

Share this post


Link to post
Share on other sites
tombu

Jimmy Bergmark's vp-outline.lsp creates a polyline in modelspace that has the outline of the selected viewport. It provides an example that optionally selects the current active viewport if in modelspace or by selection if in paperspace. Handy for me since my viewport layer is generally frozen in layouts. His blog has a 12/2/2015 link to LayoutsToDwgs.lsp at http://blog.jtbworld.com/2015/12/how-to-save-layouts-to-separate-drawings.html on his free code page that isn't working now. No mention of taking the page down, just modifying the website for mobile devices. While his site seems to be under construction at the moment the code can be found here on CadTutor at:

http://www.cadtutor.net/forum/showthread.php?21820-Modelspace-coordinates-from-paperspace-viewports&p=139494&viewfull=1#post139494

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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