Jump to content

Recommended Posts

Posted (edited)

Hi All,

 

I just found something very strange and weird! and I have no idea how can I fix it.

 

I wrote this lisp:

(defun c:que ()

(setq a "ali")

(while a

(setq d (car (entsel)))

(if (= d nil) (print "select a Line/Arc")

)

(if (/= d nil)

(progn

(setq e (entget d))

(if (or (= (cdr (assoc 0 e)) "LINE") (= (cdr (assoc 0 e)) "ARC")) (setq a nil)

)

)

)

)

 

;pt1

(setq pt1 (cdr (assoc 10 e)))

 

(command "line" pt1 (polar pt1 (/ pi 4) 5) "")

 

(princ)

)

Please download the attached DWG file and try this lisp on the drawing. The program is working on some lines but AutoCAD draw zero length line on the others!!!

 

Can somebody please explain it to me?

 

Cheers

 

AJ

 

Drawing1.dwg

Edited by alijahed
Posted
Hi All,

 

I just found something very strange and weird! and I have no idea how can I fix it.

 

I wrote this lisp:

 

How did you find that lisp and you can not fix it and at last you said that you wrote it ??????

 

Anyway , What do you want from the routine to do for you ?

Posted

Well, for start I have to say I wrote a long lisp and because I received odd results I spent some time and finally I found this bit of the program creates the problem.

Basically, I want to draw a line on another line from its start point pt1 to another point which is pt2.

If you try that lisp on those different lines that I drew, you'll see the problem. The program is working on some lines but AutoCAD draw zero length line on the others!!!

Posted

Try this .......

 

(defun c:que (/ ss)
 ; Tharwat 12.02.2011
 (if (setq ss (ssget "_:L" '((0 . "LINE,ARC"))))
   ((lambda ( i / ss1 e pt1)
      (while
    (setq ss1 (ssname ss (setq i (1+ i))))
    (setq e (entget ss1))
    (entmakex (list (cons 0 "LINE")
            (cons 10 (setq pt1 (cdr (assoc 10 e))))
            (cons 11 (polar pt1 (/ pi 4) 5))
            ))
    ))
     -1
     )
   (princ "\n No Line(s) or Arc(s) Selected !!!")
   )
 (princ)
 )

 

Tharwat

Posted

Thanks for your quick reply.

I am not that much advance in lisp yet! Can you please tell me what is wrong in mine?

Posted

Actually nothing is wrong with your codes , and it works for me in a new drawing, but with the drawing that

you uploaded it works on some lines and others not , but these lines which are not working with you can

change their start or end points and it would work on them as well as on the others .

 

I do not know how did you make these lines ( the way you draw them) because the problem is with their coordinates .

 

Regards,

 

Tharwat

Posted

It seems stupid but I think Autocad doesn't get the right information through osnap!

I drew a couple of points and lines and etc. on the acadiso template.

 

I wrote this:

(defun c:test5 (/ ptl xl yl pt)

(setq ptl (getpoint "\nSelect a Point"))

(setq pt (polar ptl (/ pi 2) 8.0))

(command "point" pt)

(princ)

)

 

once you zoom in and with the osnap "Node" "Endpoint" on, you have no problem but from a longer distance the point will draw on the snap point!!!!

 

:cry::cry::cry:

Posted
It seems stupid but I think Autocad doesn't get the right information through osnap!

I drew a couple of points and lines and etc. on the acadiso template.

 

I wrote this:

 

 

once you zoom in and with the osnap "Node" "Endpoint" on, you have no problem but from a longer distance the point will draw on the snap point!!!!

 

:cry::cry::cry:

 

Nothing's wrong except the localizing arguments .(/ ptl pt) and (command "point" "_non" pt) This would prevent the osnap to control

or change the location of the picked point by the user .

 

And for the routine you pick a point and after that you re-specified the location of the point to be 8.0 units away with 90.0 degrees .

 

What did you expect from your codes to draw other than that ?

 

Tharwat

Guest kruuger
Posted
Actually nothing is wrong with your codes , and it works for me in a new drawing, but with the drawing that

you uploaded it works on some lines and others not , but these lines which are not working with you can

change their start or end points and it would work on them as well as on the others .

 

I do not know how did you make these lines ( the way you draw them) because the problem is with their coordinates .

 

Regards,

 

Tharwat

When you draw something with command !!ALWAYS!! before set OSMODE to 0 (zero) and everything will be ok. try this:

(defun c:que (/ OSM a d e pt1)
 (setq OSM (getvar 'OSMODE))
 (setq a "ali")
 (while a
   (setq d (car (entsel)))
   (if (= d nil) (print "select a Line/Arc"))
   (if (/= d nil)
     (progn
       (setq e (entget d))
       (if (or (= (cdr (assoc 0 e)) "LINE") (= (cdr (assoc 0 e)) "ARC")) (setq a nil))
     )
   )
 )
 (setq pt1 (cdr (assoc 10 e)))
 (setvar 'OSMODE 0)
 (command "_line" pt1 (polar pt1 (/ pi 4) 5) "")
 (setvar 'OSMODE OSM)
 (princ)
)

kruuger

Posted

Just make sure the osnap override "_non" is placed before each point.

eg.

(command "_line" [color=red]"_NON[/color]" pt1 [color=red]"_NON[/color]" (polar pt1 (/ pi 4) 5) "")

 

 

When you draw something with command !!ALWAYS!! before set OSMODE to 0 (zero) and everything will be ok. try this:

(defun c:que (/ OSM a d e pt1)
 (setq OSM (getvar 'OSMODE))
 (setq a "ali")
 (while a
   (setq d (car (entsel)))
   (if (= d nil) (print "select a Line/Arc"))
   (if (/= d nil)
     (progn
       (setq e (entget d))
       (if (or (= (cdr (assoc 0 e)) "LINE") (= (cdr (assoc 0 e)) "ARC")) (setq a nil))
     )
   )
 )
 (setq pt1 (cdr (assoc 10 e)))
 (setvar 'OSMODE 0)
 (command "_line" pt1 (polar pt1 (/ pi 4) 5) "")
 (setvar 'OSMODE OSM)
 (princ)
)

kruuger

Posted
When you draw something with command !!ALWAYS!! before set OSMODE to 0 (zero) and everything will be ok. try this:

(defun c:que (/ OSM a d e pt1)
 .........
...........
 (setvar 'OSMODE 0)
 (command "_line" pt1 (polar pt1 (/ pi 4) 5) "")
 (setvar 'OSMODE OSM)
 (princ)
)

kruuger

 

Did you downloaded the dwg that were given by the OP Kruuger ?

 

Did you read my reply No# 8 ?

 

The routine that I have given were with enmakex function and it does not require to turn off the Osmode .

besides that , As I mentioned earlier and Alanjt did as well with an example , the "_non" would handle that issue .

 

Regards,

 

Tharwat

Guest kruuger
Posted
Did you downloaded the dwg that were given by the OP Kruuger ?

 

Did you read my reply No# 8 ?

 

The routine that I have given were with enmakex function and it does not require to turn off the Osmode .

besides that , As I mentioned earlier and Alanjt did as well with an example , the "_non" would handle that issue .

 

Regards,

 

Tharwat

hello Tharwat

alijahed was asking why his code it's not working and i gave him the answer.

maybe next time he want to use more command and then better is turn off osnap.

 

of course your code don't need change osmode. you draw line in "silent" mode :)

take care

kruuger

Posted
hello Tharwat

alijahed was asking why his code it's not working and i gave him the answer.

maybe next time he want to use more command and then better is turn off osnap.

 

of course your code don't need change osmode. you draw line in "silent" mode :)

take care

kruuger

 

 

Completely agree . :thumbsup:

 

Thank you .

 

Tharwat

Posted

?

 

(defun c:TESt (/ ss)
 (vl-load-com)
 (if (setq ss (ssget '((0 . "ARC,LINE"))))
   ((lambda (i / d)
      (repeat i
        (entmakex (append '((0 . "LINE"))
                          (vl-remove-if
                            (function (lambda (x) (vl-position (car x) '(-1 0 5 11 40 50 51 100))))
                            (setq d (entget (ssname ss (setq i (1- i)))))
                          )
                          (list (cons 11 (polar (cdr (assoc 10 d)) (/ pi 4.) 5.)))
                  )
        )
      )
    )
     (sslength ss)
   )
 )
 (princ)
)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...