Reference line is not getting deleted properly.

Reference line is not getting deleted properly.

jlee107
Contributor Contributor
643 Views
7 Replies
Message 1 of 8

Reference line is not getting deleted properly.

jlee107
Contributor
Contributor
Hello, I need help with deleting a line and exploding the block after command is executed. What I'm trying to do is create a reference line by selecting two points and then use midpoint of that line to place base point of a block with angle orientation. When current code is executed, it does place the block as I intended, but it does not delete the reference line or explode after. I tried using "(ssdel (list connectingLine))" and when I do use this code instead of entde1, somehow it bypasses the code and does allow block to be exploded. The reference remains still un-deleted though... please help
 
(defun c:WQ (/ startPoint endPoint connectingLine)
  (defun insert-block-at-midpoint (midpoint rotation length)
    (setq roundedLength
          (+ (fix length) (- (if (< (rem (fix length) 100) 50) 50 100) (rem (fix length) 100))))

    (setq blockName (strcat (rtos roundedLength 2 0) "ec"))
    (if (or (tblobjname "BLOCK" blockName)
            (findfile (strcat blockName ".dwg")))
        (command "_.INSERT" blockName "_non" midpoint 1.0 1.0 rotation)
        (alert (strcat "Block '" blockName "' missing"))))

  (setq startPoint (getpoint "\nSelect first and second points: "))
  (setq endPoint (getpoint))

  (setq connectingLine (entmake (list '(0 . "LINE") (cons 10 startPoint) (cons 11 endPoint))))

  (setq midPoint (list (/ (+ (car startPoint) (car endPoint)) 2.0)
                        (/ (+ (cadr startPoint) (cadr endPoint)) 2.0)
                        0.0))

  (setq rotation (angle startPoint endPoint))
  (setq rotation (/ (* rotation 180.0) pi))

  (insert-block-at-midpoint midPoint rotation (distance startPoint endPoint))

  ;; Delete the connecting line using entdel
  (entdel connectingLine)

  ;; Execute explode command after a delay
  (vl-cmdf "_.EXPLODE" "L" "")
)

(princ "\nType WT to use the command.")
0 Likes
Accepted solutions (2)
644 Views
7 Replies
Replies (7)
Message 2 of 8

EnM4st3r
Advocate
Advocate

use entlast to get the ename of the created line then you can delete it later with entdel:

  (entmake (list '(0 . "LINE") (cons 10 startPoint) (cons 11 endPoint)))
  (setq connectingLine (entlast))

 

 i would do the same with the block. safe the ename of the block after placing it

(insert-block-at-midpoint midPoint rotation (distance startPoint endPoint))
  (setq newBlock (entlast))

 

then you can easily delte and explode them

;; Delete the connecting line using entdel
  (entdel connectingLine)

  ;; Execute explode command after a delay
  (vl-cmdf "_.EXPLODE" newBlock "")


but for you command you do not need the line. Calculation of midpoint and rotation works exactly the same even without the line

0 Likes
Message 3 of 8

jlee107
Contributor
Contributor

1st Pic

jlee107_1-1704243040995.png

2nd Pic

jlee107_2-1704243141708.png

 

 

3rd Pic

jlee107_0-1704243014607.png

4th Pic

jlee107_3-1704243182996.png

 

So the first picture shows the area I'm trying to insert. 2nd picture shows hollow red circles indicating two points I'm using to create a line. 3rd pic shows the result after I changed the code according to your suggestion. It still shows that there is a white line being created and the block entity isn't exploded. 4th pic shows how it should look like after executing the command and choosing two points. I'm not sure what's wrong with the code. I believe your suggestion should work, but there might be something that I'm not catching.

 

Below is a code I've changed.

 

(defun c:WQ (/ startPoint endPoint connectingLine)
  (defun insert-block-at-midpoint (midpoint rotation length)
    (setq roundedLength
          (+ (fix length) (- (if (< (rem (fix length) 100) 50) 50 100) (rem (fix length) 100))))

    (setq blockName (strcat (rtos roundedLength 2 0) "ec"))
    (if (or (tblobjname "BLOCK" blockName)
            (findfile (strcat blockName ".dwg")))
        (command "_.INSERT" blockName "_non" midpoint 1.0 1.0 rotation)
        (alert (strcat "Block '" blockName "' missing"))))

  (setq startPoint (getpoint "\nSelect first and second points: "))
  (setq endPoint (getpoint))

  (entmake (list '(0 . "LINE") (cons 10 startPoint) (cons 11 endPoint)))
  (setq connetingLine (entlast))

  (setq midPoint (list (/ (+ (car startPoint) (car endPoint)) 2.0)
                        (/ (+ (cadr startPoint) (cadr endPoint)) 2.0)
                        0.0))

  (setq rotation (angle startPoint endPoint))
  (setq rotation (/ (* rotation 180.0) pi))

  (insert-block-at-midpoint midPoint rotation (distance startPoint endPoint))
  (setq newBlock (entlast))

  ;; Delete the connecting line using entdel
  (entdel connectingLine)

  ;; Execute explode command after a delay
  (vl-cmdf "_.EXPLODE" newBlock "")
)

(princ "\nType WQ to use the command.")

 

0 Likes
Message 4 of 8

Kent1Cooper
Consultant
Consultant

I agree that it would do what it does without making the Line.  You don't ever use the connectingLine variable for any purpose other than to delete it, and the midpoint is calculated from the picked points without reference to the Line, so the Line itself is not doing anything for you -- I would forget it, and therefore also eliminate the deleting of it later.

 

Are there any messages when it doesn't work?  What is the command-line history when you run it?  Does it sometimes work, or never?

 

A possibility:  Your Block is defined for uniform scaling, but you're giving it both X and Y scale factors?  [I admit I haven't checked in your earlier sample drawing in a different topic.]

 

A more likely possibility, at least about the Block not being Exploded:  The EXPLODE command, when used in either a (command) or (vl-cmdf) function, for some reason can Explode only one thing, even if you feed it a selection set of multiple objects, unless you jump through some hoops to get around that limitation.  It therefore does not want an Enter "" to complete the selection.  With that "" included as you have it, that recalls the latest pre-AutoLisp-routine command issued.  If that was U, that will immediately reverse the Exploding that was just done.  I suppose it's possible that it might also reverse the deleting of the Line.  If that's what has been happening, you'll see it in the command-line history.  Remove that from your code, or learn about the hoops to jump through to make Exploding work with it included.

Kent Cooper, AIA
0 Likes
Message 5 of 8

jlee107
Contributor
Contributor

Pic1

jlee107_0-1704247498218.png

 

The reason behind why I wanted to create a line and delete it was because I wanted to see a physical line reference when I select two points. Like you said there is no need to make a line, but it was just a personal preference. If I don't have creating line function, then it doesn't show the distance of two points during the selection but rather shows x,y coordinates (Pic1). If there is another way to do show distance of two selected point during selection, I would be open to it. Before I had to measure the distance then find a block to fit that distance. This is why I wanted to show distance during the selection process of two points.

 

Initially I wrote a code with just selecting two points, placing a block, then explode. This worked perfectly fine until I decided to add creating line function. I kinda understand about jumping through the hoops to get around limitation, but that might cause a problem later on if I decide to add more functions to the code. I think possibility you are referring to about "reverse the deleting of the line" is true. Below is the code that worked before without the line but I would be open to more suggestions.  

(defun c:WQ (/ startPoint endPoint)
  (defun insert-block-at-midpoint (midpoint rotation length)
    (setq roundedLength
          (+ (fix length) (- (if (< (rem (fix length) 100) 50) 50 100) (rem (fix length) 100))))

    (setq blockName (strcat (rtos roundedLength 2 0) "ec"))
    (if (or (tblobjname "BLOCK" blockName)
            (findfile (strcat blockName ".dwg")))
        (command "_.INSERT" blockName "_non" midpoint 1.0 1.0 rotation)
        (alert (strcat "Block '" blockName "' missing"))))

  (setq startPoint (getpoint "\nSelect first point: "))
  (setq endPoint (getpoint "\nSelect second point: "))

  (setq midPoint (list (/ (+ (car startPoint) (car endPoint)) 2.0)
                        (/ (+ (cadr startPoint) (cadr endPoint)) 2.0)
                        0.0))

  (setq rotation (angle startPoint endPoint))
  (setq rotation (/ (* rotation 180.0) pi))

  (insert-block-at-midpoint midPoint rotation (distance startPoint endPoint))
  (setq newBlock (entlast))

  ;; Explode the newly inserted block
  (vl-cmdf "_.EXPLODE" newBlock "")

  (princ "\nType WQ to use the command.")
)

 

0 Likes
Message 6 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

@jlee107 wrote:

.... If there is another way to do show distance of two selected point during selection, I would be open to it. ....


If you have Coordinates display turned on in the status bar, and set to the right display option [relative displacement], then if you give the first point as a reference in the (getpoint) function for setting the second point, you will see a "rubber band" in the drawing area from the first point to the cursor location, and the distance and angle of the displacement between them in the status bar, as you move the cursor around to pick the second point:

(setq startPoint (getpoint "\nSelect first point: "))
(setq endPoint (getpoint startPoint "\nSelect second point: "))

Kent Cooper, AIA
0 Likes
Message 7 of 8

jlee107
Contributor
Contributor
Thank you this is much better.
0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor
Accepted solution

 I wanted to see a physical line reference when I select two points.

 

(setq startPoint (getpoint "\nSelect first point: "))
(setq endPoint (getpoint startpoint "\nSelect second point: "))
0 Likes