Jump to content

Move obcjects from Paperspace to Model and scale them


ziele_o2k

Recommended Posts

I have a dwg file exported from program. This program exports everything to paperspace. I whant to move everything to model space.

I think that chspace command won't work because there is no viewports in layouts.

Every dwg file has only one layout.

After moving objects to model space i would like also to scale them

Link to comment
Share on other sites

The following request will be:

Make a different scale

Images to put near

To encircle the image

Do this for 100500 files at a time

Collect all of the different files in one file ...

So ?

Link to comment
Share on other sites

Once again. For steel detailing, I'm useing AdvanceSteel. This program make documentation in separate dwgs in paper space (one drawing - one dwg, model space is empty). All i whant to get, is open dwg, copy or move all objects from paper space to model space, scale objects in model space (scale factor is saved in attribute from drawing table), save file and exit.

To open multiple drawings I will use LeeMac script writer.

 

_exportlayout will not work, because this exports layout to new dwg.

 

First sample:

(defun m2ms ( / ps ss pts vp )
 (setq ps (car (layoutlist)))
 (setvar 'CTAB ps)
 (if (setq ss (ssget "_X" (list (cons 410 ps))))
   (progn
     (setq pts (LM:ssboundingbox ss))
     (setq vp (cd:ACX_AddViewport (cd:ACX_Paper) (car pts) (-(caadr pts) (caar pts)) (-(cadadr pts) (cadar pts)) 1 3))
     (vla-put-CustomScale vp 0.1) ; to change
     (vl-cmdf "_.chspace" ss "")
   )
 )
 (princ)
)

 

Subfunctions:

(defun LM:ssboundingbox ( sel / idx llp ls1 ls2 obj urp )
   (repeat (setq idx (sslength sel))
       (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))
       (if (and (vlax-method-applicable-p obj 'getboundingbox)
                (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list obj 'llp 'urp))))
           )
           (setq ls1 (cons (vlax-safearray->list llp) ls1)
                 ls2 (cons (vlax-safearray->list urp) ls2)
           )
       )
   )
   (if (and ls1 ls2)
       (mapcar '(lambda ( a b ) (apply 'mapcar (cons a b))) '(min max) (list ls1 ls2))
   )
)

(defun cd:ACX_AddViewport (Space Pb Width Height HJust VJust / obj)
 (setq Pb (trans Pb 1 0))
 (cond 
   ( (= HJust 1) (setq Pb (list (+ (car Pb) (/ Width 2)) (cadr Pb) (caddr Pb))) )
   ( (= HJust 3) (setq Pb (list (- (car Pb) (/ Width 2)) (cadr Pb) (caddr Pb))) )
 )
 (cond 
   ( (= VJust 1) (setq Pb (list (car Pb) (- (cadr Pb) (/ Height 2)) (caddr Pb))) )
   ( (= VJust 3) (setq Pb (list (car Pb) (+ (cadr Pb) (/ Height 2)) (caddr Pb))) )
 )
 (vla-Display  
   (setq obj
     (vla-AddPViewport
       Space
       (vlax-3d-point Pb)
       Width
       Height
     )
   )
   :vlax-true
 )
  obj
)

(defun cd:ACX_Paper ()
 (setq *cd-PaperSpace* (vla-get-PaperSpace (cd:ACX_ADoc)))
)

(defun cd:ACX_ADoc ()
 (or
   *cd-ActiveDocument*
   (setq *cd-ActiveDocument*
     (vla-get-ActiveDocument (vlax-get-acad-object))
   )
 )
 *cd-ActiveDocument*
)

Link to comment
Share on other sites

I am starting to think more like Roy_043 just use copy and paste and re-scale. Paste each layout next to the last with a gap.

 

Maratovich may be on the money also create a new dwg and just insert into a master dwg.

 

I do not use advance steel but it would seem odd to not have a make a single file with multiple layouts for a project have you checked that also.

Link to comment
Share on other sites

I can do this on the VBA. Or make an .exe program

Processing without opening files.

But I need to know everything.

For example, what scale?

Link to comment
Share on other sites

Hi,

 

Try this program and let me know how you get on with it.

 

(defun c:test (/ doc scl sel int pnt ent lst mvs)
 ;;------------------------------------;;
 ;;	Tharwat - Date: 26.07.2017	;;
 ;; Move objects from Paper Space to	;;
 ;; Model Space and scale them as per	;;
 ;; the scale factor specified from	;;
 ;; the user.				;;
 ;;------------------------------------;;
 (if (and (or (/= (getvar 'ctab) "Model")
              (alert "Command is not allowed in Model Space <!>")
          )
          (setq scl (getdist "\nSpecify the scale factor :"))
          (princ "\nSelect objects to move to Model space then to scale :")
          (setq doc (vla-get-activedocument (vlax-get-acad-object))
                int -1
                pnt (vlax-3d-point '(0. 0. 0.))
                sel (ssget "_:L" '((0 . "~VIEWPORT")))
          )
     )
   (progn
     (while (setq ent (ssname sel (setq int (1+ int))))
       (setq lst (cons (vlax-ename->vla-object ent) lst))
     )
     (if (apply 'and
                (setq mvs (vlax-invoke
                            doc
                            'copyobjects
                            lst
                            (vla-get-modelspace doc)
                          )
                )
         )
       (progn
         (mapcar '(lambda (obj) (vla-scaleentity obj pnt scl)) mvs)
         (mapcar 'vla-delete lst)
       )
     )
   )
 )
 (princ)
) (vl-load-com)

Link to comment
Share on other sites

Hi,

 

Try this program and let me know how you get on with it.

 

(defun c:test (/ doc scl sel int pnt ent lst mvs)
 ;;------------------------------------;;
 ;;	Tharwat - Date: 26.07.2017	;;
 ;; Move objects from Paper Space to	;;
 ;; Model Space and scale them as per	;;
 ;; the scale factor specified from	;;
 ;; the user.				;;
 ;;------------------------------------;;
 (if (and (or (/= (getvar 'ctab) "Model")
              (alert "Command is not allowed in Model Space <!>")
          )
          (setq scl (getdist "\nSpecify the scale factor :"))
          (princ "\nSelect objects to move to Model space then to scale :")
          (setq doc (vla-get-activedocument (vlax-get-acad-object))
                int -1
                pnt (vlax-3d-point '(0. 0. 0.))
                sel (ssget "_:L" '((0 . "~VIEWPORT")))
          )
     )
   (progn
     (while (setq ent (ssname sel (setq int (1+ int))))
       (setq lst (cons (vlax-ename->vla-object ent) lst))
     )
     (if (apply 'and
                (setq mvs (vlax-invoke
                            doc
                            'copyobjects
                            lst
                            (vla-get-modelspace doc)
                          )
                )
         )
       (progn
         (mapcar '(lambda (obj) (vla-scaleentity obj pnt scl)) mvs)
         (mapcar 'vla-delete lst)
       )
     )
   )
 )
 (princ)
) (vl-load-com)

 

Works great, that is exactly what I need.

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