Model Space and Paper Space

Model Space and Paper Space

Browning_Zed
Advocate Advocate
2,543 Views
9 Replies
Message 1 of 10

Model Space and Paper Space

Browning_Zed
Advocate
Advocate

If an ActiveX function requires obtaining a pointer to model space or paper space to execute. In this case, the obtaining a pointer:
(vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object)))
will only execute in model space.

And the obtaining a pointer:
(vla-get-PaperSpace (vla-get-ActiveDocument (vlax-get-acad-object)))
will be executed only in layout.
Is it possible to remove this restriction so that the function that requires obtaining a pointer is executed

both in model space and in paper space?

0 Likes
Accepted solutions (2)
2,544 Views
9 Replies
Replies (9)
Message 2 of 10

hak_vz
Advisor
Advisor
(vla-get-ActiveSpace (vla-get-ActiveDocument (vlax-get-acad-object)))

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 10

Browning_Zed
Advocate
Advocate

This doesn't work in my case.

0 Likes
Message 4 of 10

_gile
Consultant
Consultant
Accepted solution

Hi,

(setq doc (vla-get-ActiveDocument (vlax-get-acad-object))
	space
	 (if (= (getvar 'cvport) 1)
	   (vla-get-PaperSpace doc)
	   (vla-get-ModelSpace doc)
	 )
  )

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 10

hak_vz
Advisor
Advisor
Accepted solution

Or you can use

 

(vla-get-ActiveLayout (vla-get-activedocument(vlax-get-acad-object)))

 

 

Command: (vla-get-Name(vla-get-ActiveLayout (vla-get-activedocument(vlax-get-acad-object))))
"Layout1"

 

 

Command: (vla-get-Name(vla-get-ActiveLayout (vla-get-activedocument(vlax-get-acad-object))))
"Model"

 

 

Or you can use code from @_gile depending what you want.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 6 of 10

Browning_Zed
Advocate
Advocate

Unfortunately, I have not been able to achieve the desired result. It doesn't work for me. I'll give code. It converts an LW Polyline (as well as other entities) to a multiline.

 

(Conv2Mline ( / )
   (vla-AddMline
     (vla-get-ModelSpace
       (vla-get-ActiveDocument
         (vlax-get-acad-object)
       )
     )
     (LM:SafearrayVariant vlax-VBDouble (apply 'append (LM:ent->pts (car (entsel)) 3)))
   )
)
;; Entity to Point List  -  Lee Mac
;; Returns a list of WCS points describing or approximating the supplied entity, else nil if the entity is not supported.
;; ent - [ent] Entity name to be described by point list (POINT/LINE/ARC/CIRCLE/LWPOLYLINE/POLYLINE/ELLIPSE/SPLINE)
;; acc - [num] Positive number determining the point density for non-linear objects
(defun LM:ent->pts ( ent acc / ang bul cen cls di1 di2 enx inc itm lst num ocs rad tot typ vt1 vt2 vtl )
    (setq enx (entget ent)
          typ (cdr (assoc 0 enx))
    )
    (cond
        (   (= "POINT" typ)
            (list (cdr (assoc 10 enx)))
        )
        (   (= "LINE" typ)
            (mapcar '(lambda ( x ) (cdr (assoc x enx))) '(10 11))
        )
        (   (or (= "ARC" typ) (= "CIRCLE" typ))
            (if (= "ARC" typ)
                (setq ang (cdr (assoc 50 enx))
                      tot (rem (+ pi pi (- (cdr (assoc 51 enx)) ang)) (+ pi pi))
                      num (fix (+ 1.0 1e-8 (* acc (/ tot (+ pi pi)))))
                      inc (/ tot (float num))
                      num (1+ num)
                )
                (setq ang 0.0
                      tot (+ pi pi)
                      num (fix (+ 1e-8 acc))
                      inc (/ tot (float num))
                )
            )
            (setq cen (cdr (assoc 010 enx))
                  rad (cdr (assoc 040 enx))
                  ocs (cdr (assoc 210 enx))
            )
            (repeat num
                (setq lst (cons (trans (polar cen ang rad) ocs 0) lst)
                      ang (+ ang inc)
                )
            )
            (reverse lst)
        )
        (   (or (= "LWPOLYLINE" typ)
                (and (= "POLYLINE" typ) (zerop (logand (logior 16 64) (cdr (assoc 70 enx)))))
            )
            (if (= "LWPOLYLINE" typ)
                (setq vtl (LM:ent->pts:lwpolyvertices enx))
                (setq vtl (LM:ent->pts:polyvertices   ent))
            )
            (if (setq ocs (cdr (assoc 210 enx))
                      cls (= 1 (logand 1 (cdr (assoc 70 enx))))
                )
                (setq vtl (append vtl (list (cons (caar vtl) 0.0))))
            )
            (while (setq itm (car vtl))
                (setq vtl (cdr vtl)
                      vt1 (car itm)
                      bul (cdr itm)
                      lst (cons (trans vt1 ocs 0) lst)
                )
                (if (and (not (equal 0.0 bul 1e-8)) (setq vt2 (caar vtl)))
                    (progn
                        (setq rad (/ (* (distance vt1 vt2) (1+ (* bul bul))) 4.0 bul)
                              cen (polar vt1 (+ (angle vt1 vt2) (- (/ pi 2.0) (* 2.0 (atan bul)))) rad)
                              rad (abs rad)                            
                              tot (* 4.0 (atan bul))
                              num (fix (+ 1.0 1e-8 (* acc (/ (abs tot) (+ pi pi)))))
                              inc (/ tot (float num))
                              ang (+ (angle cen vt1) inc)
                        )                        
                        (repeat (1- num)
                            (setq lst (cons (trans (polar cen ang rad) ocs 0) lst)
                                  ang (+ ang inc)
                            )
                        )
                    )
                )
            )
            (reverse (if cls (cdr lst) lst))
        )
        (   (= "ELLIPSE" typ)
            (setq di1 (vlax-curve-getdistatparam ent (vlax-curve-getstartparam ent))
                  di2 (vlax-curve-getdistatparam ent (vlax-curve-getendparam   ent))
                  di2 (- di2 1e-8)
            )
            (while (< di1 di2)
                (setq lst (cons (vlax-curve-getpointatdist ent di1) lst)
                      rad (distance '(0.0 0.0) (vlax-curve-getfirstderiv ent (vlax-curve-getparamatdist ent di1)))
                      di1 (+ di1 (/ di2 (1+ (fix (* acc (/ di2 rad (+ pi pi)))))))
                )
            )
            (reverse (if (vlax-curve-isclosed ent) lst (cons (vlax-curve-getendpoint ent) lst)))
        )
        (   (= "SPLINE" typ)
            (setq di1 (vlax-curve-getdistatparam ent (vlax-curve-getstartparam ent))
                  di2 (vlax-curve-getdistatparam ent (vlax-curve-getendparam   ent))
                  lst (list (vlax-curve-getstartpoint ent))
                  inc (/ (- di2 di1) (float acc))
                  di1 (+ di1 inc)
            )
            (repeat (1- (fix (+ 1e-8 acc)))
                (setq lst (cons (vlax-curve-getpointatdist ent di1) lst)
                      di1 (+ di1 inc)
                )
            )
            (reverse (if (vlax-curve-isclosed ent) lst (cons (vlax-curve-getendpoint ent) lst)))
        )
    )
)
(defun LM:ent->pts:lwpolyvertices ( enx / elv lst vtx )
    (setq elv (list (cdr (assoc 38 enx))))
    (while (setq vtx (assoc 10 enx))
        (setq enx (cdr (member vtx enx))
              lst (cons (cons (append (cdr vtx) elv) (cdr (assoc 42 enx))) lst)
        )
    )
    (reverse lst)
)
(defun LM:ent->pts:polyvertices ( ent / lst vte vtx )
    (setq vte (entnext ent)
          vtx (entget  vte)
    )   
    (while (= "VERTEX" (cdr (assoc 0 vtx)))
        (setq lst (cons (cons (cdr (assoc 10 vtx)) (cdr (assoc 42 vtx))) lst)
              vte (entnext vte)
              vtx (entget  vte)
        )
    )
    (reverse lst)
)
(defun LM:SafearrayVariant ( datatype data )
 (vlax-make-variant
   (vlax-safearray-fill
     (vlax-make-safearray datatype
       (cons 0 (1- (length data)))
     )
     data
   )    
 )
)

(Conv2Mline)

 

 

0 Likes
Message 7 of 10

Browning_Zed
Advocate
Advocate

I tried again but that also doesn't work. I posted the code above this post.

0 Likes
Message 8 of 10

_gile
Consultant
Consultant

@hak_vz take care, if a viewport is activated in the current paper space (vla-get-ActiveLayout ...) will return the paper space layout despite the active space is model space.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 10

_gile
Consultant
Consultant
(defun Conv2Mline (/)
  (vla-AddMline
    (if	(= (getvar 'cvport) 1)
      (vla-get-PaperSpace (vla-get-ActiveDocument (vlax-get-acad-object)))
      (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object)))
    )
    (LM:SafearrayVariant vlax-VBDouble (apply 'append (LM:ent->pts (car (entsel)) 3)))
  )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 10 of 10

Browning_Zed
Advocate
Advocate
Thanks a lot! The function now works as expected.
0 Likes