Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

entsel not working properly

11 REPLIES 11
Reply
Message 1 of 12
rosader
571 Views, 11 Replies

entsel not working properly

I am writing a lisp that prompts the user to select a beam line and then it changes the layer of the line (to a layer for moment frame beams) and adds triangle blocks to each end rotated 90 degrees perpendicular to selected line.
When I run the lisp, it prompts to select beam line to convert to MF line but when I do it says *invalid selection* and then prompts you to "select objects" so it's not recognizing the line saved with entsel. When I proceed with "select objects" it disregards the lisp and has you change properties manually. Can anyone show me what I'm doing wrong?

Here is the lisp code:

(vl-load-com)
(defun c:b2mf (/ l0 l1 l2 e1 p1 p2 beamang)
  (c:dunn_get_lay)
  (setq l0 (getvar "clayer") ;get current layer
l1 (strcat level "_S-BEAM-MF") ;set layer for moment frame beam
l2 (strcat level "_S-COLS-MF") ;set layer for moment frame triangle
e1 (car (entsel "\nSelect Beam to Convert: ")) ;selects beam and saves to e1
p1 (cdr (assoc 10 (entget e1))) ;gets first point of beam from e1
p2 (cdr (assoc 11 (entget e1))) ;gets second point of beam from e1
beamang (cdr (assoc 50 (entget e1))) ;gets angle of beam e1
  );setq
  (while (/= e1 nil)
    (progn
      (command "CHPROP" e1 "la" l1 "") ;select line saved to e1 and change layer to l1
      (setvar "clayer" l2) ;sets the layer for inserting moment frame triangles
      (command "INSERT" "MFTRIANGLE.dwg" p1 1 1 (+ beamang 90.0)) ;insert moment triangle block at point p1 rotated 90 degrees relative to e1
      (command "INSERT" "MFTRIANGLE.dwg" p2 1 1 (+ beamang 180.0)) ;insert moment triangle block at point p2 rotated 180 degrees relative to e1
    );progn
    (setq e1 (car (entsel "\nSelect Beam to Convert or <Enter> to Quit: "))
  );while
    (setvar "clayer" l0) ;returns current layer to l0
    (princ "Converted to Moment Frame Beam")
    (princ))
);defun
Labels (6)
11 REPLIES 11
Message 2 of 12
Kent1Cooper
in reply to: rosader

You need to complete the object selection in the CHPROP command with Enter [""]:

 

(command "CHPROP" e1 "" "la" l1 "")

Kent Cooper, AIA
Message 3 of 12
Moshe-A
in reply to: rosader

@rosader hi,

 

this is my untested fix  😀

 

Moshe

 

(vl-load-com)

(defun c:b2mf (/ l0 l1 l2 e1 p1 p2 beamang)
 (c:dunn_get_lay)
  (setq l0 (getvar "clayer") ;get current layer
        l1 (strcat level "_S-BEAM-MF") ;set layer for moment frame beam
        l2 (strcat level "_S-COLS-MF") ;set layer for moment frame triangle
       
  );setq
  
  (while (setq e1 (car (entsel "\nSelect Beam to Convert: "))) ;selects beam and saves to e1
   (setq p1 (cdr (assoc 10 (entget e1))) ;gets first point of beam from e1
         p2 (cdr (assoc 11 (entget e1))) ;gets second point of beam from e1
         beamang (cdr (assoc 50 (entget e1))) ;gets angle of beam e1
   )
   (command "CHPROP" e1 "" "la" l1 "") ;select line saved to e1 and change layer to l1
   (setvar "clayer" l2) ;sets the layer for inserting moment frame triangles
   (command "INSERT" "MFTRIANGLE.dwg" p1 1 1 (+ beamang 90.0))  ;insert moment triangle block at point p1 rotated 90 degrees relative to e1
   (command "INSERT" "MFTRIANGLE.dwg" p2 1 1 (+ beamang 180.0)) ;insert moment triangle block at point p2 rotated 180 degrees relative to e1
  );while
    
  (setvar "clayer" l0) ;returns current layer to l0
  (princ "Converted to Moment Frame Beam")
    
  (princ)
);defun

 

Message 4 of 12
paullimapa
in reply to: rosader

It fails because right after your code request for e1 it requests entget of the following:

 

e1 (car (entsel "\nSelect Beam to Convert: ")) ;selects beam and saves to e1
p1 (cdr (assoc 10 (entget e1))) ;gets first point of beam from e1
p2 (cdr (assoc 11 (entget e1))) ;gets second point of beam from e1
beamang (cdr (assoc 50 (entget e1))) ;gets angle of beam e1

 

But if nothing is selected then p1, p2 & beamang won't be retrieved...

Then you again request for e1 at the end of while loop here:

 

 );progn
    (setq e1 (car (entsel "\nSelect Beam to Convert or <Enter> to Quit: "))
  );while

 

But since within your while loop you don't request for p1, p2 & beamang, then the code fails.

Though I cannot fully test since I don't have function c:dunn_get_lay, give this version a try:

 

(defun c:b2mf (/ l0 l1 l2 e1 p1 p2 beamang)
  (vl-load-com)
  (c:dunn_get_lay)
  (setq l0 (getvar "clayer") ;get current layer
        l1 (strcat level "_S-BEAM-MF") ;set layer for moment frame beam
        l2 (strcat level "_S-COLS-MF") ;set layer for moment frame triangle
  );setq
  (while (setq e1 (car (entsel "\nSelect Beam to Convert or <Enter> to Quit: "))) ;selects beam and saves to e1
    (if (eq "LINE" (cdr(assoc 0 (entget e1)))) ; check if LINE selected
      (progn
       (setq p1 (cdr (assoc 10 (entget e1))) ;gets first point of beam from e1
             p2 (cdr (assoc 11 (entget e1))) ;gets second point of beam from e1
             beamang (cdr (assoc 50 (entget e1))) ;gets angle of beam e1
	   )
       (command "_.CHPROP" e1 "" "_la" l1 "") ;select line saved to e1 and change layer to l1
       (setvar "clayer" l2) ;sets the layer for inserting moment frame triangles
       (command "_.INSERT" "MFTRIANGLE.dwg" p1 1 1 (+ beamang 90.0)) ;insert moment triangle block at point p1 rotated 90 degrees relative to e1
       (command "_.INSERT" "MFTRIANGLE.dwg" p2 1 1 (+ beamang 180.0)) ;insert moment triangle block at point p2 rotated 180 degrees relative to e1
	  )
      (princ"\nObject Selected Not a Line.")
	) ; if
  );while
  (setvar "clayer" l0) ;returns current layer to l0
  (princ "Convert to Moment Frame Beam completed")
  (princ)
);defun

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 12
rosader
in reply to: paullimapa

Thank You. I tried yours and it definitely changes the layer of the line correctly now. After that though, it has you manually rotating the mf triangle block at p1 and then it does not insert the mf triangle block at p2. Does autolisp not recognize that input (+ beamang 90.0) for the rotation angle?

Message 6 of 12
paullimapa
in reply to: rosader

there's no 50 assoc pair for LINE objects

so the way to get the angle is this:

(defun RtD (r) (* 180.0 (/ r pi))) ; function to convert radians to degrees
(setq beamang (rtd(angle p1 p2))) ; returns angle of line

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 7 of 12
rosader
in reply to: paullimapa

I'm not sure what I'm doing wrong. I put the code in to convert radians to degrees. I did the angle of beamang based on p1 and p2 and it still wants me to manually set rotation of block.

Message 8 of 12
paullimapa
in reply to: rosader

does MFTRIANGLE.dwg contain attributes?

post this block you want to insert in


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 9 of 12
rosader
in reply to: paullimapa

No attributes. Here is the block

Message 10 of 12
paullimapa
in reply to: rosader

if block comes in with 0 rotation it'll look like this when you have a 45 degree line vs 0 degree

paullimapa_0-1687213346144.png

depending on the rotation angle you want to rotate at p1 vs p2

this is what you'll have to figure out to program into your code


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 11 of 12
komondormrex
in reply to: rosader

used 2d solid instead of block. rotation or drafting of solids should be tuned.

 

 

;************************************************************************************************************************

(defun draw_solid (point_vertex back_point_vertex)
	(vla-addsolid (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
				  (vlax-3d-point (trans point_vertex 1 0))
				  (vlax-3d-point (trans (polar point_vertex (- (angle point_vertex back_point_vertex) (/ pi 6)) 6) 1 0))
				  (vlax-3d-point (trans (polar point_vertex (+ (angle point_vertex back_point_vertex) (/ pi 6)) 6) 1 0))
				  (vlax-3d-point (trans (polar point_vertex (+ (angle point_vertex back_point_vertex) (/ pi 6)) 6) 1 0))
	)
)

;************************************************************************************************************************

(defun c:b2mf ( / beam beam_layer mf_triangle_layer)
	(setq beam (car (entsel "\Pick a beam line: "))
		  beam_layer (strcat (getvar 'clayer) "_S-BEAM-MF")
		  mf_triangle_layer (strcat (getvar 'clayer) "_S-COLS-MF")
	)
	(entmod (subst (cons 8 beam_layer) (assoc 8 (entget beam)) (entget beam)))
	(draw_solid (cdr (assoc 10 (entget beam))) (cdr (assoc 11 (entget beam))))
	(entmod (subst (cons 8 mf_triangle_layer) (assoc 8 (entget (entlast))) (entget (entlast))))
	(draw_solid (cdr (assoc 11 (entget beam))) (cdr (assoc 10 (entget beam))))
	(entmod (subst (cons 8 mf_triangle_layer) (assoc 8 (entget (entlast))) (entget (entlast))))
	(princ)
)

;************************************************************************************************************************

 

Message 12 of 12
Sea-Haven
in reply to: rosader

Using pline with start width 0.0 end width the size of arrow is a alternative to solid.

SeaHaven_0-1687305097973.png

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report