+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Junior Member
    Discipline
    Multi-disciplinary
    Fett2oo5's Discipline Details
    Occupation
    Mech/Struct Engineering, Automation and Systems Development
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2013
    Join Date
    Nov 2011
    Location
    Tomball, TX
    Posts
    16

    Default Automation for details in viewports [SOLVED]

    Registered forum members do not see this ad.

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




    Link to all the above images on Imgur.com

    LISP routine explained in reply

    *Edit* Added example .dwg file: View Parts in Layout.dwg
    Last edited by Fett2oo5; 30th Dec 2015 at 09:42 pm. Reason: Marked as solved

  2. #2
    Junior Member
    Discipline
    Multi-disciplinary
    Fett2oo5's Discipline Details
    Occupation
    Mech/Struct Engineering, Automation and Systems Development
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2013
    Join Date
    Nov 2011
    Location
    Tomball, TX
    Posts
    16

    Default

    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.
    Code:
    ;;; 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.

  3. #3
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    This will performs Steps 1-4:
    Code:
    (defun c:bbx ( / box off sel tmp )
        (if
            (not
                (and
                    (setq off (getenv "LMac\\bbx-off"))
                    (setq off (distof off 2))
                )
            )
            (setq off (atof (setenv "LMac\\bbx-off" "0.75")))
        )
        (if (setq tmp (getdist (strcat "\nSpecify offset <" (rtos off) ">: ")))
            (setenv "LMac\\bbx-off" (rtos (setq off tmp) 2))
        )
        (if (setq sel (ssget))
            (if (setq box (LM:ssboundingbox sel)
                      box (mapcar '(lambda ( a b ) (mapcar a b (list off off))) '(- +) box)
                )
                (entmake
                    (append
                       '(   (000 . "LWPOLYLINE")
                            (100 . "AcDbEntity")
                            (100 . "AcDbPolyline")
                            (008 . "Defpoints")
                            (090 . 4)
                            (070 . 1)
                        )
                        (mapcar '(lambda ( x ) (cons 10 (mapcar '(lambda ( y ) ((eval y) box)) x)))
                           '(
                                (caar   cadar)
                                (caadr  cadar)
                                (caadr cadadr)
                                (caar  cadadr)
                            )
                        )
                    )
                )
            )
        )
        (princ)
    )
    
    ;; Selection Set Bounding Box  -  Lee Mac
    ;; Returns a list of the lower-left and upper-right WCS coordinates of a
    ;; rectangular frame bounding all objects in a supplied selection set.
    ;; s - [sel] Selection set for which to return bounding box
    
    (defun LM:ssboundingbox ( s / a b i m n o )
        (repeat (setq i (sslength s))
            (if
                (and
                    (setq o (vlax-ename->vla-object (ssname s (setq i (1- i)))))
                    (vlax-method-applicable-p o 'getboundingbox)
                    (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list o 'a 'b))))
                )
                (setq m (cons (vlax-safearray->list a) m)
                      n (cons (vlax-safearray->list b) n)
                )
            )
        )
        (if (and m n)
            (mapcar '(lambda ( a b ) (apply 'mapcar (cons a b))) '(min max) (list m n))
        )
    )
    (vl-load-com) (princ)
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  4. #4
    Junior Member
    Discipline
    Multi-disciplinary
    Fett2oo5's Discipline Details
    Occupation
    Mech/Struct Engineering, Automation and Systems Development
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2013
    Join Date
    Nov 2011
    Location
    Tomball, TX
    Posts
    16

    Default

    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.

  5. #5
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Quote Originally Posted by Fett2oo5 View Post
    WOW Lee! You never cease to amaze. This time with your speed.

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

    Quote Originally Posted by Fett2oo5 View Post
    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:
    Code:
    (defun c:cvp ( / ent enx lst )
        (cond
            (   (= 1 (getvar 'tilemode))
                (princ "\nCommand not allowed in Modelspace.")
            )
            (   (= 1 (getvar 'cvport))
                (princ "\nPlease activate a viewport.")
            )
            (   (while
                    (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect polyline frame: ")))
                        (cond
                            (   (= 7 (getvar 'errno))
                                (princ "\nMissed, try again.")
                            )
                            (   (null ent) nil)
                            (   (/= "LWPOLYLINE" (cdr (assoc 0 (setq enx (entget ent)))))
                                (princ "\nThe selected object is not a polyline.")
                            )
                            (   (setq lst (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) enx)))
                                (vla-zoomwindow (LM:acapp)
                                    (vlax-3D-point (apply 'mapcar (cons 'min lst)))
                                    (vlax-3D-point (apply 'mapcar (cons 'max lst)))
                                )
                                (vla-put-mspace (vla-get-activedocument (LM:acapp)) :vlax-false)
                            )
                        )
                    )
                )
            )
        )
        (princ)
    )
    
    ;; Application Object  -  Lee Mac
    ;; Returns the VLA Application Object
    
    (defun LM:acapp nil
        (eval (list 'defun 'LM:acapp 'nil (vlax-get-acad-object)))
        (LM:acapp)
    )
        
    (vl-load-com) (princ)
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  6. #6
    Junior Member
    Discipline
    Multi-disciplinary
    Fett2oo5's Discipline Details
    Occupation
    Mech/Struct Engineering, Automation and Systems Development
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2013
    Join Date
    Nov 2011
    Location
    Tomball, TX
    Posts
    16

    Default

    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.

  7. #7
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    That's great to hear, you're entirely welcome - I'm glad that you could benefit from the thread.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  8. #8
    Super Member
    Computer Details
    tombu's Computer Details
    Operating System:
    Windows 7 64-bit
    Computer:
    Dell
    Discipline
    Civil
    tombu's Discipline Details
    Occupation
    Design Analyst
    Discipline
    Civil
    Details
    Small Street & Stormwater projects. Traffic Calming and other issues.
    Using
    Civil 3D 2018
    Join Date
    Dec 2010
    Location
    Tallahassee, FL USA
    Posts
    717

    Default

    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...-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/showth...l=1#post139494

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Registered forum members do not see this ad.

    There is also this.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. Layout with Multiple Viewports to DWG with the Viewports 'Flattened' Out
    By tkrejci in forum AutoCAD Drawing Management & Output
    Replies: 3
    Last Post: 23rd Aug 2011, 08:45 pm
  2. Replies: 0
    Last Post: 16th Sep 2010, 10:20 am
  3. Revsurf multiple option automation
    By KRBeckman in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 30th Mar 2010, 12:55 pm
  4. Binding multiple Drawings Automation
    By Cad_Jockeys in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 6th Jan 2009, 05:28 am
  5. How to clip details or callouts from multiple Xref dwg?
    By Cadkiller in forum AutoCAD Drawing Management & Output
    Replies: 1
    Last Post: 9th Apr 2006, 10:17 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts