ViewPort - Get entities from ViewPort

ViewPort - Get entities from ViewPort

richie_hodgson
Collaborator Collaborator
1,331 Views
2 Replies
Message 1 of 3

ViewPort - Get entities from ViewPort

richie_hodgson
Collaborator
Collaborator

Hi, I am going a little potty over something simple. I found a nice lisp that puts the viewport rotation into a north block which works fine when there is a plain viewport, but if you have a polygonal viewport it gets confused between the defining polyline and the viewport so I tried to get it to selection set only the viewport but I am getting  ; error: bad argument type: lentityp nil error. I am using AutoCAD 2016 and Civil3D 2016.

 

(defun c:rn()

(prompt "\nSelect Objects by Window") ; my tweek

(setq tw (ssget '((0 . "VIEWPORT")))); my tweek

(setq tw (ssadd ent tw)); my tweek

 

;(setq tw(entget(car(entsel" Select a Viewport:")))) ;original code

 

(setq new (cdr (assoc 0 tw)))

(cond

((= new "VIEWPORT")(setq rt(cdr(assoc 51 tw))))

((= new "LWPOLYLINE")(setq temp (entget(cdr (assoc 330 tw))))(setq rt(cdr(assoc 51 temp))))

)

(setq en(car(entsel" Select North Arrow: ")))

(setq elist(entget en))

(setq elist(subst (cons 50 rt)(assoc 50 elist) elist))

(entmod elist)

(princ)

)

 

Hope you can help.

 

 

 

Richie
0 Likes
Accepted solutions (1)
1,332 Views
2 Replies
Replies (2)
Message 2 of 3

Shneuph
Collaborator
Collaborator
Accepted solution

with vlisp:

(Defun c:rn (/ RH-vlVP RH-na)
  (prompt "\nSelect Viewport")
  (setq RH-vlVP (vlax-ename->vla-object (ssname
					   (ssget "_+.:E:S" '((0 . "VIEWPORT")));thanks lee-mac
					   0);ssname
		   );vlax-ename->...
	);setq
  (setq RH-na (vlax-ename->vla-object (car (entsel "\nSelect North Arrow: "))))
  (princ (strcat
	   "\nBlock rotation: "
	   (rtos (cvunit (vla-get-rotation RH-na) "Radians" "Degrees") 2 3)
	   "° matched to\nVP Rotation: "
	   (rtos (cvunit (vla-get-twistangle RH-vlvp) "Radians" "Degrees") 2 3)
	   "°")
	 );princ
  (vla-put-rotation RH-na (vla-get-twistangle RH-vlvp))
  (princ)
  )
---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 3 of 3

richie_hodgson
Collaborator
Collaborator

Brilliant.

Richie
0 Likes