Can't figure out what is wrong with this LISP

Can't figure out what is wrong with this LISP

Anonymous
Not applicable
2,219 Views
22 Replies
Message 1 of 23

Can't figure out what is wrong with this LISP

Anonymous
Not applicable

hi, everyone,

I wrote a lisp myself but the lisp telling bad ssget list. how to resolve it. I was trying so much time but i can't figure out my problem. could anyone solve me?

thanks advance to everyone

hussain

 

(defun c:cl ()
(setq ss (ssget '((0 "insert"))))
(setq slen (sslength ss))
(setq index 0)
(repeat slen
(setq ab (entget (ssname ss index)))
(setq ac (cdr (assoc 10 ab)))
(setq p1 (getpoint ss))
(setq p2 (getpoint "\nenter another point: "))

(setq ang (angle p1 p2))
(command "line" p1 p2 "c" "")
(setq index (1+ index))
)
(princ)
)

 

 

0 Likes
Accepted solutions (3)
2,220 Views
22 Replies
Replies (22)
Message 2 of 23

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

hi, everyone,

I wrote a lisp myself but the lisp telling bad ssget list. how to resolve it. I was trying so much time but i can't figure out my problem. could anyone solve me?

thanks advance to everyone

hussain

 

(defun c:cl ()
(setq ss (ssget '((0 . "insert")))) ; missing dot
(setq slen (sslength ss))
(setq index 0)
(repeat slen
(setq ab (entget (ssname ss index)))
(setq ac (cdr (assoc 10 ab)))
;(setq p1 (getpoint ss)) ; did you meant to use the ac point?
(setq p2 (getpoint "\nenter another point: "))

(setq ang (angle ac p2)) ; what are you going to do with angle?
(command "line" "_non" ac "_non" p2 "c" "") ; "c is wrong, what that should be for?" turn off osnaps as well
(setq index (1+ index))
)
(princ)
)

 

 


 

0 Likes
Message 3 of 23

dbhunia
Advisor
Advisor

Hi

 


@Anonymous wrote:

hi, everyone,

I wrote a lisp myself but the lisp telling bad ssget list. how to resolve it. I was trying so much time but i can't figure out my problem. could anyone solve me?

thanks advance to everyone

hussain

 

(defun c:cl ()
(setq ss (ssget '((0 "insert"))))
(setq slen (sslength ss))
(setq index 0)
(repeat slen
(setq ab (entget (ssname ss index)))
(setq ac (cdr (assoc 10 ab)))
(setq p1 (getpoint ss))
(setq p2 (getpoint "\nenter another point: "))

(setq ang (angle p1 p2))
(command "line" p1 p2 "c" "")
(setq index (1+ index))
)
(princ)
)

 

 


The highlighted line would be...

 

(setq ss (ssget '((0 . "insert"))))


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 4 of 23

Anonymous
Not applicable

thank you so much beekeecz for your email.

i meant the angle. the line wants to draw at 45 degrees then goes a straight line again - 45 degrees to connect other blocks(kindly see the image). this is i want to do it but i can't draw a line to connect to block as i attached the image .

thanks 

hussain 

0 Likes
Message 5 of 23

ВeekeeCZ
Consultant
Consultant

THIS is a very similar issue that came up recently, might be inspirational to you as well.

 

I'll try look into this one too...

I saw no 45° on the image. Would you send a dwg with a suggested connection for any angular situation? (any different than an ideal horizontal)

Message 6 of 23

Anonymous
Not applicable

hi beekeecz

I attached the drawing here. kindly find below.

0 Likes
Message 7 of 23

dbhunia
Advisor
Advisor
Accepted solution

Try this ...... (For this particular Block).......Because your line Start & End point of line is not at the base point of the Block....

 

(defun C:JB (/ p1 p2 p3 p4 p5 ang ang_r h1 h2)
(setq osm (getvar "osmode"))
(command "cmdecho" 0)
(command "osmode" 0)
(setq ss (ssget '((0 . "insert"))))
(cond ((= 2 (sslength ss))
	(Setq P1 (cdr (assoc 10 (entget (ssname ss 0)))))
	(Setq P1 (list (nth 0 P1) (+ 0.2 (nth 1 P1)) (nth 2 P1)));;;;;;;;;;;;
	(Setq P2 (cdr (assoc 10 (entget (ssname ss 1)))))
	(Setq P2 (list (nth 0 P2) (+ 0.2 (nth 1 P2)) (nth 2 P2)));;;;;;;;;;;;
	(Setq P3 (getpoint "\nPick Point for Horizontal Line: "))
	(setq ang (getangle "\nEnter Angle: "))
	(setq ang_r (- ang (/ pi 2)))
	(setq a1 (distance p1 (list (nth 0 P1) (nth 1 P3) (nth 2 P3))))
	(setq h1 (/ a1 (cos ang_r)))
	(setq b1 (* h1 (sin ang_r)))
	(setq a2 (distance p2 (list (nth 0 P2) (nth 1 P3) (nth 2 P3))))
	(setq h2 (/ a2 (cos ang_r)))
	(setq b2 (* h2 (sin ang_r)))
	(Setq P4 (polar P1 (angle p1 (list (nth 0 P2) (nth 1 P1) (nth 2 P2))) b1))
	(Setq P4 (list (nth 0 P4) (nth 1 P3) (nth 2 P4)))
	(Setq P5 (polar P2 (angle p2 (list (nth 0 P1) (nth 1 P2) (nth 2 P1))) b2))
	(Setq P5 (list (nth 0 P5) (nth 1 P3) (nth 2 P5)))
	(command "_.pline" p1 p4 p5 p2 "")
      )
    ((> 2 (sslength ss)) (princ "\nMinimum two Blocks need to select."))
    ((< 2 (sslength ss)) (princ "\nMore than two Blocks selected."))
)
(command "osmode" osm)
(command "cmdecho" 1)
(princ)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 8 of 23

ВeekeeCZ
Consultant
Consultant
Accepted solution

Sorry, busy on a training.

If your blocks are horizontally aligned, this simple approach will cover it.

 

(defun c:OffConnect ( / p1 p2)

  (if (and (setq p1 (car (entsel "\nLeft block: ")))
           (setq p1 (trans (cdr (assoc 10 (entget p1))) 0 1))
           (setq p2 (car (entsel "\nRight block: ")))
           (setq p2 (trans (cdr (assoc 10 (entget p2))) 0 1))
           )
    (command "_.pline"
             "_from" p1 
"_none" "@0,0.2" "_none" "@0.3,-0.6" "_none" (strcat "@" (rtos (- (distance p1 p2) 0.6) 2 4) ",0") "_none" "@0.3,0.6" "")) (princ) )

 

Message 9 of 23

Anonymous
Not applicable

hi dbhunia

 

thank you so much dbhunia for creating me.

1.may i know why you add this function(sin and cos). it is very hard to understand. 

2.why you add 0.2? what is the reason? 

(list (nth 0 P1) (+ 0.2 (nth 1 P1)) (nth 2 P1)))

 

0 Likes
Message 10 of 23

dbhunia
Advisor
Advisor

@Anonymous wrote:

hi dbhunia

 

thank you so much dbhunia for creating me.

1.may i know why you add this function(sin and cos). it is very hard to understand. 

2.why you add 0.2? what is the reason? 

(list (nth 0 P1) (+ 0.2 (nth 1 P1)) (nth 2 P1)))

 


 

In your drawing you want the line starts above 0.2mm from the insertion point of the Block so I added that value with Y co-ordinate (as your Block has been placed in 1:1 scale) only keeping the other X,Z Co-ordinates of P1 & P2 as it is....

 

This is not the only way to get Y co-ordinate with  0.2mm offset from the insertion point of the Block .......


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 11 of 23

Anonymous
Not applicable

hi beekeez

thanks a lot, you and dbhunia.both are doing very great job.i appreciate your effort.

thanks

hussain

0 Likes
Message 12 of 23

Anonymous
Not applicable

@ВeekeeCZ wrote:

Sorry, busy on a training.

If your blocks are horizontally aligned, this simple approach will cover it.

 

(defun c:OffConnect ( / p1 p2)

  (if (and (setq p1 (car (entsel "\nLeft block: ")))
           (setq p1 (trans (cdr (assoc 10 (entget p1))) 0 1))
           (setq p2 (car (entsel "\nRight block: ")))
           (setq p2 (trans (cdr (assoc 10 (entget p2))) 0 1))
           )
    (command "_.pline"
             "_from" p1 
"_none" "@0,0.2" "_none" "@0.3,-0.6" "_none" (strcat "@" (rtos (- (distance p1 p2) 0.6) 2 4) ",0") "_none" "@0.3,0.6" "")) (princ) )

 


hi beekeecz

you created this AutoLISP for only horizontal side only. how about another side, I mean vertical (left side & right side).i modified your lisp but i did not get actually what i wanted to do.,although it little helps to me. kindly check this.i want to make the line by selected block to vertically (right and left side) which i marked red colour.i hope you understand everything. I appreciate you what to do for me.

 

 

(defun c:blrr ( / p1 p2)

(setq ss (ssget '((0 . "insert"))))

;(setq p1 (car (entsel "\nLeft block: ")))
(setq p1 (trans (cdr (assoc 10 (entget (ssname ss 0)))) 0 1))
;(setq p2 (car (entsel "\nRight block: ")))
(setq p2 (trans (cdr (assoc 10 (entget (ssname ss 1)))) 0 1))

(command "_.pline"
"_from" p1
"_none" "@0,0.0"
"_none" "@-0.6,0.6"
"_none" pause
"_none" pause

p2

"")
(princ)
)

 

0 Likes
Message 13 of 23

ВeekeeCZ
Consultant
Consultant

It's not difficult, just simple math. 

 

(defun c:OffConnect (/ ss p1 p2 pt ag)
  
  (if (and (setq ss (ssget '((0 . "INSERT"))))
           (setq p1 (trans (cdr (assoc 10 (entget (ssname ss 0)))) 0 1))
           (setq p2 (trans (cdr (assoc 10 (entget (ssname ss 1)))) 0 1))
           (setq ag (angle p1 p2))
           )
    (command "_.pline"
             "_none" (setq pt (polar p1 (+ ag (/ pi 2)) 0.2))
             "_none" (setq pt (polar pt (- ag (/ pi 3)) 0.8))
             "_none" (polar pt ag (- (distance p1 p2) 0.8))
             "_none" (polar p2 (+ ag (/ pi 2)) 0.2)
             ""))
  (princ)
  )
0 Likes
Message 14 of 23

Anonymous
Not applicable

@ВeekeeCZ wrote:

It's not difficult, just simple math. 

 

(defun c:OffConnect (/ ss p1 p2 pt ag)
  
  (if (and (setq ss (ssget '((0 . "INSERT"))))
           (setq p1 (trans (cdr (assoc 10 (entget (ssname ss 0)))) 0 1))
           (setq p2 (trans (cdr (assoc 10 (entget (ssname ss 1)))) 0 1))
           (setq ag (angle p1 p2))
           )
    (command "_.pline"
             "_none" (setq pt (polar p1 (+ ag (/ pi 2)) 0.2))
             "_none" (setq pt (polar pt (- ag (/ pi 3)) 0.8))
             "_none" (polar pt ag (- (distance p1 p2) 0.8))
             "_none" (polar p2 (+ ag (/ pi 2)) 0.2)
             ""))
  (princ)
  )

thank you so much.

this is, I am really trying to get this last 3days to work myself, but the result is the only get frustration then I post here to get advice those who familiar in the AutoLISP program. I am so happy. I deeply appreciate your help. could i have your email id?

 

how about more than 2 blocks by selecting ssget . it just adds again (i mean setq p1, setq p2 and setq p3 etc...) to get more block. here, where will add "while" expression to get automatically connect the block with a line.

0 Likes
Message 15 of 23

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

... how about more than 2 blocks by selecting ssget . it just adds again (i mean setq p1, setq p2 and setq p3 etc...) to get more block. here, where will add "while" expression to get automatically connect the block with a line.


 

The issue is the workflow. Figure out HOW would you determine the order. If you select them one by one, it's obvious. If they are in a straight line, it's obvious... But what if they are not. Think like a programmer... 

0 Likes
Message 16 of 23

Anonymous
Not applicable

@ВeekeeCZ wrote:

@Anonymous wrote:

... how about more than 2 blocks by selecting ssget . it just adds again (i mean setq p1, setq p2 and setq p3 etc...) to get more block. here, where will add "while" expression to get automatically connect the block with a line.


 

The issue is the workflow. Figure out HOW would you determine the order. If you select them one by one, it's obvious. If they are in a straight line, it's obvious... But what if they are not. Think like a programmer.


 you wrote the message above.i can understand little by little, but not completely.

anyway, the order is, either it could be a straight line or vertical line. this is my expectation from you.

i tried again your code with few modifications, but the message pops up  "bad argument 2d/3d point". i attached here modification code. i know sure it's wrong.

 

(defun c:OffConnect (/ ss p1 p2 pt ag)

(setq ss (ssget '((0 . "INSERT"))))
(setq sa (sslength ss))
(setq i 0)
(repeat sa
(setq sb (cdr (entget (ssname ss i))))
(setq sc (car(assoc 10 sb)))
(setq i (1+ i))
;(setq p1 (trans (cdr (assoc 10 (entget (ssname ss 0)))) 0 1))
;(setq p2 (trans (cdr (assoc 10 (entget (ssname ss 1)))) 0 1))
(setq ag (angle sc sb))

(command "_.pline"
"_none" (setq pt (polar sc (- ag (/ pi 2)) 0.0))
"_none" (setq pt (polar pt (+ ag (/ pi 3)) 0.8))
"_none" (polar pt ag (- (distance sc sc) 0.8))
"_none" (polar sc (+ ag (/ pi 2)) 0.0)
""))
(princ)
)

0 Likes
Message 17 of 23

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

@ВeekeeCZ wrote:

@Anonymous wrote:

... how about more than 2 blocks by selecting ssget . it just adds again (i mean setq p1, setq p2 and setq p3 etc...) to get more block. here, where will add "while" expression to get automatically connect the block with a line.


 

The issue is the workflow. Figure out HOW would you determine the order. If you select them one by one, it's obvious. If they are in a straight line, it's obvious... But what if they are not. Think like a programmer.


 you wrote the message above.i can understand little by little, but not completely.

anyway, the order is, either it could be a straight line or vertical line. this is my expectation from you.

i tried again your code with few modifications, but the message pops up  "bad argument 2d/3d point". i attached here modification code. i know sure it's wrong.

 

(defun c:OffConnect (/ ss p1 p2 pt ag)

(setq ss (ssget '((0 . "INSERT"))))
(setq sa (sslength ss))
(setq i 0)
(repeat sa
(setq sb (cdr (entget (ssname ss i))))
(setq sc (car(assoc 10 sb)))
(setq i (1+ i))
;(setq p1 (trans (cdr (assoc 10 (entget (ssname ss 0)))) 0 1))
;(setq p2 (trans (cdr (assoc 10 (entget (ssname ss 1)))) 0 1))
(setq ag (angle sc sb))

(command "_.pline"
"_none" (setq pt (polar sc (- ag (/ pi 2)) 0.0))
"_none" (setq pt (polar pt (+ ag (/ pi 3)) 0.8))
"_none" (polar pt ag (- (distance sc sc) 0.8))
"_none" (polar sc (+ ag (/ pi 2)) 0.0)
""))
(princ)
)


You've probably meant something like this. 

(defun c:OffConnect (/ ss p1 p2 pt ag)
  
  (setq ss (ssget '((0 . "INSERT"))))
  (setq i -1)
  (repeat (1- (sslength ss))
    (setq i (1+ i))
    (setq p1 (trans (cdr (assoc 10 (entget (ssname ss i)))) 0 1))
    (setq p2 (trans (cdr (assoc 10 (entget (ssname ss (1+ i))))) 0 1))
    (setq ag (angle p1 p2))
    
    (command "_.pline"
             "_none" (setq pt (polar p1 (- ag (/ pi 2)) 0.0))
             "_none" (setq pt (polar pt (+ ag (/ pi 3)) 0.8))
             "_none" (polar pt ag (- (distance p1 p2) 0.8))
             "_none" (polar p2 (+ ag (/ pi 2)) 0.0)
             ""))
  (princ)
  )

If you run into trouble, try the "Fence" selection method.

0 Likes
Message 18 of 23

Anonymous
Not applicable

@ВeekeeCZ wrote:

@Anonymous wrote:

@ВeekeeCZ wrote:

@Anonymous wrote:

... how about more than 2 blocks by selecting ssget . it just adds again (i mean setq p1, setq p2 and setq p3 etc...) to get more block. here, where will add "while" expression to get automatically connect the block with a line.


 

The issue is the workflow. Figure out HOW would you determine the order. If you select them one by one, it's obvious. If they are in a straight line, it's obvious... But what if they are not. Think like a programmer.


 you wrote the message above.i can understand little by little, but not completely.

anyway, the order is, either it could be a straight line or vertical line. this is my expectation from you.

i tried again your code with few modifications, but the message pops up  "bad argument 2d/3d point". i attached here modification code. i know sure it's wrong.

 

(defun c:OffConnect (/ ss p1 p2 pt ag)

(setq ss (ssget '((0 . "INSERT"))))
(setq sa (sslength ss))
(setq i 0)
(repeat sa
(setq sb (cdr (entget (ssname ss i))))
(setq sc (car(assoc 10 sb)))
(setq i (1+ i))
;(setq p1 (trans (cdr (assoc 10 (entget (ssname ss 0)))) 0 1))
;(setq p2 (trans (cdr (assoc 10 (entget (ssname ss 1)))) 0 1))
(setq ag (angle sc sb))

(command "_.pline"
"_none" (setq pt (polar sc (- ag (/ pi 2)) 0.0))
"_none" (setq pt (polar pt (+ ag (/ pi 3)) 0.8))
"_none" (polar pt ag (- (distance sc sc) 0.8))
"_none" (polar sc (+ ag (/ pi 2)) 0.0)
""))
(princ)
)


You've probably meant something like this. 

(defun c:OffConnect (/ ss p1 p2 pt ag)
  
  (setq ss (ssget '((0 . "INSERT"))))
  (setq i -1)
  (repeat (1- (sslength ss))
    (setq i (1+ i))
    (setq p1 (trans (cdr (assoc 10 (entget (ssname ss i)))) 0 1))
    (setq p2 (trans (cdr (assoc 10 (entget (ssname ss (1+ i))))) 0 1))
    (setq ag (angle p1 p2))
    
    (command "_.pline"
             "_none" (setq pt (polar p1 (- ag (/ pi 2)) 0.0))
             "_none" (setq pt (polar pt (+ ag (/ pi 3)) 0.8))
             "_none" (polar pt ag (- (distance p1 p2) 0.8))
             "_none" (polar p2 (+ ag (/ pi 2)) 0.0)
             ""))
  (princ)
  )

If you run into trouble, try the "Fence" selection method.


hi beekeez

Alhamdulillah, thank you so much, you are a marvelous man.I deeply appreciate your helpHeartHeartHeart.

this is i really looked for 1 month.it is so amazing.

 

0 Likes
Message 19 of 23

Anonymous
Not applicable

hi beekeecz

sorry again to ask so many times. i have been using your lisp since you modified for me, even though this i really helping me.

my question is how about to connect line for the perpendicular side. i attached the image for you understand. 

(defun c:OffConnect (/ ss p1 p2 pt ag)
  
  (setq ss (ssget '((0 . "INSERT"))))
  (setq i -1)
  (repeat (1- (sslength ss))
    (setq i (1+ i))
    (setq p1 (trans (cdr (assoc 10 (entget (ssname ss i)))) 0 1))
    (setq p2 (trans (cdr (assoc 10 (entget (ssname ss (1+ i))))) 0 1))
    (setq ag (angle p1 p2))
    
    (command "_.pline"
             "_none" (setq pt (polar p1 (- ag (/ pi 2)) 0.0))
             "_none" (setq pt (polar pt (+ ag (/ pi 3)) 0.8))
             "_none" (polar pt ag (- (distance p1 p2) 0.8))
             "_none" (polar p2 (+ ag (/ pi 2)) 0.0)
             ""))
  (princ)

 

 

0 Likes
Message 20 of 23

Anonymous
Not applicable

hi beekeecz

kindly reply me for my queries

0 Likes