- Forums Home
- >
- AutoCAD Community
- >
- AutoCAD Customization Forum
- >
- Visual LISP, AutoLISP and General Customization forum
- >
- Re: entsel not working properly

Community

Visual LISP, AutoLISP and General Customization

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

This page has been translated for your convenience with an automatic translation service. This is not an official translation and may contain errors and inaccurate translations. Autodesk does not warrant, either expressly or implied, the accuracy, reliability or completeness of the information translated by the machine translation service and will not be liable for damages or losses caused by the trust placed in the translation service.
Translate

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Message 1 of 12

06-19-2023
12:26 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report

06-19-2023
12:26 PM

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

11 REPLIES 11

Message 2 of 12

06-19-2023
12:52 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report

06-19-2023
12:52 PM

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

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

Message 3 of 12

06-19-2023
12:54 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report

06-19-2023
12:54 PM

@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

06-19-2023
01:12 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report

06-19-2023
01:12 PM

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

Message 5 of 12

06-19-2023
01:35 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report

06-19-2023
01:35 PM

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

06-19-2023
01:42 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report

06-19-2023
01:42 PM

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

Message 7 of 12

06-19-2023
02:29 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report

06-19-2023
02:29 PM

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

06-19-2023
03:01 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report

06-19-2023
03:01 PM

does MFTRIANGLE.dwg contain attributes?

post this block you want to insert in

Message 9 of 12

06-19-2023
03:14 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report

Message 10 of 12

06-19-2023
03:23 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report

06-19-2023
03:23 PM

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

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

Message 11 of 12

06-20-2023
12:08 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report

06-20-2023
12:08 AM

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)
)
;************************************************************************************************************************
```

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

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