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

HELP Me fix this lisp

18 REPLIES 18
SOLVED
Reply
Message 1 of 19
Anonymous
1500 Views, 18 Replies

HELP Me fix this lisp

Anonymous
Not applicable

Hey All 
this lisp is old and worked on AutoCAD 2007 but now it doesn't work on 2020 
Please check it and here is a drawing to show what it does 
Inputs is

number to start numbering

the text beside the number 
Line name 

If we can add a command for the arrow it will great 

 

 

(defun c:mnum ()
(setvar "osmode" 0)
(setq i (getint "\n Value to start with ---->")
name (getstring "\n LINE NAME ----->")
p 0
a 0
poi '()
poi1 '()
pn '()
)
(while (= a 0)
(setq poi (cdr (assoc 10 (entget (car (entsel))))))
(if (> p 0)
(progn

(IF (and (>= (ANGLE POI POI1) (/ 11 7))
(<= (ANGLE POI POI1) (/ 33 7))
)
(SETQ MANH "MANH")
(SETQ MANH "MANH")
)
(IF (and (>= (ANGLE POI POI1) (/ 11 7))
(<= (ANGLE POI POI1) (/ 33 7))
)
(SETQ pn poi)
(SETQ pn poi1)
)
(IF (and (>= (ANGLE POI POI1) (/ 22 7))
(<= (ANGLE POI POI1) (/ 33 7))
)
(SETQ PN POI)
)
(command "-layer" "s" "MH LINE" "")
(command "-insert"
MANH
poi
""
""
POI1
(strcat "MH" (rtos (+ i p) 2 0))
)
(command "-layer" "s" "S-LINE" "")
(command "line" poi poi1 "")
(command "-layer" "s" "LINE NAME" "")
(command "-insert"
"LINE NAME"
(list (/ (+ (car poi) (car poi1)) 2)
(/ (+ (cadr poi) (cadr poi1)) 2)
)
""
""
pn
name
)
)
)
(setq poi1 poi)
(setq p (+ p 1))
)
)

0 Likes

HELP Me fix this lisp

Hey All 
this lisp is old and worked on AutoCAD 2007 but now it doesn't work on 2020 
Please check it and here is a drawing to show what it does 
Inputs is

number to start numbering

the text beside the number 
Line name 

If we can add a command for the arrow it will great 

 

 

(defun c:mnum ()
(setvar "osmode" 0)
(setq i (getint "\n Value to start with ---->")
name (getstring "\n LINE NAME ----->")
p 0
a 0
poi '()
poi1 '()
pn '()
)
(while (= a 0)
(setq poi (cdr (assoc 10 (entget (car (entsel))))))
(if (> p 0)
(progn

(IF (and (>= (ANGLE POI POI1) (/ 11 7))
(<= (ANGLE POI POI1) (/ 33 7))
)
(SETQ MANH "MANH")
(SETQ MANH "MANH")
)
(IF (and (>= (ANGLE POI POI1) (/ 11 7))
(<= (ANGLE POI POI1) (/ 33 7))
)
(SETQ pn poi)
(SETQ pn poi1)
)
(IF (and (>= (ANGLE POI POI1) (/ 22 7))
(<= (ANGLE POI POI1) (/ 33 7))
)
(SETQ PN POI)
)
(command "-layer" "s" "MH LINE" "")
(command "-insert"
MANH
poi
""
""
POI1
(strcat "MH" (rtos (+ i p) 2 0))
)
(command "-layer" "s" "S-LINE" "")
(command "line" poi poi1 "")
(command "-layer" "s" "LINE NAME" "")
(command "-insert"
"LINE NAME"
(list (/ (+ (car poi) (car poi1)) 2)
(/ (+ (cadr poi) (cadr poi1)) 2)
)
""
""
pn
name
)
)
)
(setq poi1 poi)
(setq p (+ p 1))
)
)

Labels (4)
18 REPLIES 18
Message 2 of 19
Kent1Cooper
in reply to: Anonymous

Kent1Cooper
Consultant
Consultant

First:  Define "doesn't work."  Does it not load?  Does it load, but the command name isn't recognized?  Does it accept the command, but nothing happens?  If something happens, in what way(s) does it differ from what you expect?  Are there any messages?  Etc., etc.

Kent Cooper, AIA

First:  Define "doesn't work."  Does it not load?  Does it load, but the command name isn't recognized?  Does it accept the command, but nothing happens?  If something happens, in what way(s) does it differ from what you expect?  Are there any messages?  Etc., etc.

Kent Cooper, AIA
Message 3 of 19
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

It loads but when execute the command it gives error 
Command: MNUM
Value to start with ---->0
Sewer Name ----->S
Select object:
Select object: ; error: bad argument type: lentityp nil

0 Likes

It loads but when execute the command it gives error 
Command: MNUM
Value to start with ---->0
Sewer Name ----->S
Select object:
Select object: ; error: bad argument type: lentityp nil

Message 4 of 19
Kent1Cooper
in reply to: Anonymous

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

It loads but when execute the command it gives error 
....
Select object: ; error: bad argument type: lentityp nil


That looks like the kind of error that would happen if you miss in picking something.  After that happens, type in [or paste in] at the command line:

!poi

to see whether it found an entity to work with.  If that returns a point coordinates list, then you didn't miss, and something else is going on.

Kent Cooper, AIA
0 Likes


@Anonymous wrote:

It loads but when execute the command it gives error 
....
Select object: ; error: bad argument type: lentityp nil


That looks like the kind of error that would happen if you miss in picking something.  After that happens, type in [or paste in] at the command line:

!poi

to see whether it found an entity to work with.  If that returns a point coordinates list, then you didn't miss, and something else is going on.

Kent Cooper, AIA
Message 5 of 19
CADaSchtroumpf
in reply to: Anonymous

CADaSchtroumpf
Advisor
Advisor

Your loop is infinite because the variable "a" is always at 0

You have

(setq a 0)

(while (= a o) ....

But "a" not change, and if you not select an entitie you have: error: bad argument type: lentityp nil
It is poorly constructed. I'd rather see

(while (setq a (entsel))
(setq poi (cdr (assoc 10 (entget (car a)))))

 

0 Likes

Your loop is infinite because the variable "a" is always at 0

You have

(setq a 0)

(while (= a o) ....

But "a" not change, and if you not select an entitie you have: error: bad argument type: lentityp nil
It is poorly constructed. I'd rather see

(while (setq a (entsel))
(setq poi (cdr (assoc 10 (entget (car a)))))

 

Message 6 of 19
Kent1Cooper
in reply to: Anonymous

Kent1Cooper
Consultant
Consultant

Another thing, not related to the specific question:

 

I don't see anything that sets a value to the POI1 variable [except for  '() , which is just  nil ], so there will be trouble when a function wants to use it.

Kent Cooper, AIA
0 Likes

Another thing, not related to the specific question:

 

I don't see anything that sets a value to the POI1 variable [except for  '() , which is just  nil ], so there will be trouble when a function wants to use it.

Kent Cooper, AIA
Message 7 of 19

Kent1Cooper
Consultant
Consultant

@CADaSchtroumpf wrote:

Your loop is infinite because the variable "a" is always at 0

You have

(setq a 0)

(while (= a o) ....

But "a" not change....


That's a somewhat peculiar way to do something that is not uncommon, but is usually done without setting an unchanging variable:

(while T ....

which just keeps asking whatever it's looking for, as long as you want to keep going, requiring ESCape to end it.  But I agree, there are better ways to do it, that can also be ended with Enter/space, or if you like when object selection is involved, with simply picking in empty space [emulating a way you can close Mtext].

Kent Cooper, AIA
0 Likes


@CADaSchtroumpf wrote:

Your loop is infinite because the variable "a" is always at 0

You have

(setq a 0)

(while (= a o) ....

But "a" not change....


That's a somewhat peculiar way to do something that is not uncommon, but is usually done without setting an unchanging variable:

(while T ....

which just keeps asking whatever it's looking for, as long as you want to keep going, requiring ESCape to end it.  But I agree, there are better ways to do it, that can also be ended with Enter/space, or if you like when object selection is involved, with simply picking in empty space [emulating a way you can close Mtext].

Kent Cooper, AIA
Message 8 of 19
Anonymous
in reply to: Kent1Cooper

Anonymous
Not applicable

 it did return a coordinates so something else :S 

0 Likes

 it did return a coordinates so something else :S 

Message 9 of 19
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

Thank you guys but to be honest I'm not that good and the lisp was created in 2008 so is there solution for the code  ?
or to construct a new easier lisp to do the labeling line name in the middle and the manhole sequence with circles at the ends of the line

0 Likes

Thank you guys but to be honest I'm not that good and the lisp was created in 2008 so is there solution for the code  ?
or to construct a new easier lisp to do the labeling line name in the middle and the manhole sequence with circles at the ends of the line

Message 10 of 19
pbejse
in reply to: Anonymous

pbejse
Mentor
Mentor

@Anonymous wrote:

Thank you guys but to be honest I'm not that good and the lisp was created in 2008 so is there solution for the code  ?
or to construct a new easier lisp to do the labeling line name in the middle and the manhole sequence with circles at the ends of the line


 

It should be easy, problem is understanding how it should work, knowing all conditions, and more drawing sample please.

 

0 Likes


@Anonymous wrote:

Thank you guys but to be honest I'm not that good and the lisp was created in 2008 so is there solution for the code  ?
or to construct a new easier lisp to do the labeling line name in the middle and the manhole sequence with circles at the ends of the line


 

It should be easy, problem is understanding how it should work, knowing all conditions, and more drawing sample please.

 

Message 11 of 19
Anonymous
in reply to: pbejse

Anonymous
Not applicable

Steps that lisp will do 
1- Asking for starting number for MNH 
2- Asking for the name of the pipe Line name (examples: K , K-1 , K-1-22)
3- Clicking on the line so the lisp will draw a block with MNH-# and MNH-#+1 at the ends of the line and putting the Line name in the middle 
4- after that just clicking on the lines and the sequence will repeat 
Note : Common issue I think duplicating the MNH blocks and numbers at the connection ends
is that clear enough ?
MANH.dwg  small scale  how should it look and the full network to show the example of the work to try on 
Ask me any question to help the process 

0 Likes

Steps that lisp will do 
1- Asking for starting number for MNH 
2- Asking for the name of the pipe Line name (examples: K , K-1 , K-1-22)
3- Clicking on the line so the lisp will draw a block with MNH-# and MNH-#+1 at the ends of the line and putting the Line name in the middle 
4- after that just clicking on the lines and the sequence will repeat 
Note : Common issue I think duplicating the MNH blocks and numbers at the connection ends
is that clear enough ?
MANH.dwg  small scale  how should it look and the full network to show the example of the work to try on 
Ask me any question to help the process 

Message 12 of 19
pbejse
in reply to: Anonymous

pbejse
Mentor
Mentor
Accepted solution

@Anonymous wrote:

Steps that lisp will do 
1- Asking for starting number for MNH 
2- Asking for the name of the pipe Line name (examples: K , K-1 , K-1-22)
3- Clicking on the line so the lisp will draw a block with MNH-# and MNH-#+1 at the ends of the line and putting the Line name in the middle 
4- after that just clicking on the lines and the sequence will repeat 

 


Most of the issues encountered with the OG lisp are the following

  1. Layers does not exists
  2. Blocks does not exists
  3. Missed selection
  4. Insertion scale / INSUNITS
  5. System variable ATTREQ and/or ATTDIA.

Here's what I did:

I'm guessing the first selection is a Manhole Block and the suceeding selections are LINES. [ modified the code to also accept a block for selection.

 

When any of these blocks are not found, the program will terminate

    (tblsearch "BLOCK" "LINE NAME")
    (tblsearch "BLOCK" "MANH")

 

Added the option to add the layers if it does not exist [ You can change this to suit your requirement ]

Note: I did not include the option for linetype.

(foreach itm '(("SEWER NAME" 4)("S-LINE" 220) ("Sewer_Manh" 7)) 
  (if (not (tblsearch "Layer" (Car itm)))    
	  (entmake (append
		     (list (cons 0 "LAYER")
	                 (cons 100 "AcDbSymbolTableRecord")
	                 (cons 100 "AcDbLayerTableRecord")
			 (cons 70 0)
			 )
		     (mapcar '(lambda (a b)
				(cons a b)) '(2 62) itm))
		   )
    	)
  )

Here's the modified code

(Defun C:mnum ( / rtd Base poi1 sel  poi poi1 ang ent)
(defun rtd (a) (/ (* a 180.0) pi))

(setvar 'Attreq 1)
(setvar 'Attdia 0)
(setvar 'Insunits 6);<-- just an observation 


(foreach itm '(("SEWER NAME" 4)("S-LINE" 220) ("Sewer_Manh" 7)) 
  (if (not (tblsearch "Layer" (Car itm)))    
	  (entmake (append
		     (list (cons 0 "LAYER")
	                 (cons 100 "AcDbSymbolTableRecord")
	                 (cons 100 "AcDbLayerTableRecord")
			 (cons 70 0)
			 )
		     (mapcar '(lambda (a b)
				(cons a b)) '(2 62) itm))
		   )
    	)
  )
  
(or MHNumber (setq MHNumber 0))
(or SNDef (setq SNDef "K"))  
(setq MHNumber (cond
	     ((getint (strcat "\nValue to start with"
			       (if MHNumber
				 (strcat " <" (itoa MHNumber) ">: ") ": " ))))
	     (MHNumber))
	   )
(if
  (and
    (tblsearch "BLOCK" "LINE NAME")
    (tblsearch "BLOCK" "MANH")
    (Setq Base (entsel "\nSelect Select first Manhole"))
    (Setq poi1 (cdr (assoc 10 (setq ent (entget (car Base))))))
    (setq SNDef (getstring (strcat "\nSewer Name ["
	(cond (SPName) ("K")) "]: ")) SPName
				  (cond ((/= SNDef "") (strcase SNDef)) (SPName) ("K"))
				  )
    )

(while
    (progn
        (setvar 'errno 0)
        (setq sel (entsel "\nSelect Sewer Line: " ))
        (cond
            (   (= 7 (getvar 'errno))
                (princ "\nMissed, try again.")
            )
            (   (= 'ename (type (car sel)))
	     	(if (not (wcmatch (cdr (assoc 0 (setq ent (entget (car sel))))) "LINE,INSERT"))
		  	(princ "\nInvalid Object Selected.")
		  (progn
		  	(setq poi (cdr (assoc 10 ent)))
			(setq ang (angle poi1 poi)
			      ang (if (and (> ang (/ pi 2)) (<= ang (* pi 1.5))
					)  (+ ang pi) ang ))
			  
			(setvar 'clayer "Sewer_Manh")  
			(command "-insert" "MANH" "non" poi  "" "" "non" (rtd ang) (strcat "MH" (rtos MHNumber 2 0)))
			(setvar 'clayer "S-LINE")
			(command "line" "non" poi "non" poi1 "")
			(setvar 'clayer "SEWER NAME")  
			(command "-insert"  "LINE NAME"
					 (list (/ (+ (car poi) (car poi1)) 2)
					       (/ (+ (cadr poi) (cadr poi1)) 2)
					 ) "" "" (rtd ang) SPName )
  		        (setq poi1 poi MHNumber (1+ MHNumber)) 
			(princ (strcat "\nNext Number is: " (itoa MHNumber)))  
			  )
		     )
	        )
	    )
        )
     )
  )(princ)
 )

HTH


@Anonymous wrote:

Steps that lisp will do 
1- Asking for starting number for MNH 
2- Asking for the name of the pipe Line name (examples: K , K-1 , K-1-22)
3- Clicking on the line so the lisp will draw a block with MNH-# and MNH-#+1 at the ends of the line and putting the Line name in the middle 
4- after that just clicking on the lines and the sequence will repeat 

 


Most of the issues encountered with the OG lisp are the following

  1. Layers does not exists
  2. Blocks does not exists
  3. Missed selection
  4. Insertion scale / INSUNITS
  5. System variable ATTREQ and/or ATTDIA.

Here's what I did:

I'm guessing the first selection is a Manhole Block and the suceeding selections are LINES. [ modified the code to also accept a block for selection.

 

When any of these blocks are not found, the program will terminate

    (tblsearch "BLOCK" "LINE NAME")
    (tblsearch "BLOCK" "MANH")

 

Added the option to add the layers if it does not exist [ You can change this to suit your requirement ]

Note: I did not include the option for linetype.

(foreach itm '(("SEWER NAME" 4)("S-LINE" 220) ("Sewer_Manh" 7)) 
  (if (not (tblsearch "Layer" (Car itm)))    
	  (entmake (append
		     (list (cons 0 "LAYER")
	                 (cons 100 "AcDbSymbolTableRecord")
	                 (cons 100 "AcDbLayerTableRecord")
			 (cons 70 0)
			 )
		     (mapcar '(lambda (a b)
				(cons a b)) '(2 62) itm))
		   )
    	)
  )

Here's the modified code

(Defun C:mnum ( / rtd Base poi1 sel  poi poi1 ang ent)
(defun rtd (a) (/ (* a 180.0) pi))

(setvar 'Attreq 1)
(setvar 'Attdia 0)
(setvar 'Insunits 6);<-- just an observation 


(foreach itm '(("SEWER NAME" 4)("S-LINE" 220) ("Sewer_Manh" 7)) 
  (if (not (tblsearch "Layer" (Car itm)))    
	  (entmake (append
		     (list (cons 0 "LAYER")
	                 (cons 100 "AcDbSymbolTableRecord")
	                 (cons 100 "AcDbLayerTableRecord")
			 (cons 70 0)
			 )
		     (mapcar '(lambda (a b)
				(cons a b)) '(2 62) itm))
		   )
    	)
  )
  
(or MHNumber (setq MHNumber 0))
(or SNDef (setq SNDef "K"))  
(setq MHNumber (cond
	     ((getint (strcat "\nValue to start with"
			       (if MHNumber
				 (strcat " <" (itoa MHNumber) ">: ") ": " ))))
	     (MHNumber))
	   )
(if
  (and
    (tblsearch "BLOCK" "LINE NAME")
    (tblsearch "BLOCK" "MANH")
    (Setq Base (entsel "\nSelect Select first Manhole"))
    (Setq poi1 (cdr (assoc 10 (setq ent (entget (car Base))))))
    (setq SNDef (getstring (strcat "\nSewer Name ["
	(cond (SPName) ("K")) "]: ")) SPName
				  (cond ((/= SNDef "") (strcase SNDef)) (SPName) ("K"))
				  )
    )

(while
    (progn
        (setvar 'errno 0)
        (setq sel (entsel "\nSelect Sewer Line: " ))
        (cond
            (   (= 7 (getvar 'errno))
                (princ "\nMissed, try again.")
            )
            (   (= 'ename (type (car sel)))
	     	(if (not (wcmatch (cdr (assoc 0 (setq ent (entget (car sel))))) "LINE,INSERT"))
		  	(princ "\nInvalid Object Selected.")
		  (progn
		  	(setq poi (cdr (assoc 10 ent)))
			(setq ang (angle poi1 poi)
			      ang (if (and (> ang (/ pi 2)) (<= ang (* pi 1.5))
					)  (+ ang pi) ang ))
			  
			(setvar 'clayer "Sewer_Manh")  
			(command "-insert" "MANH" "non" poi  "" "" "non" (rtd ang) (strcat "MH" (rtos MHNumber 2 0)))
			(setvar 'clayer "S-LINE")
			(command "line" "non" poi "non" poi1 "")
			(setvar 'clayer "SEWER NAME")  
			(command "-insert"  "LINE NAME"
					 (list (/ (+ (car poi) (car poi1)) 2)
					       (/ (+ (cadr poi) (cadr poi1)) 2)
					 ) "" "" (rtd ang) SPName )
  		        (setq poi1 poi MHNumber (1+ MHNumber)) 
			(princ (strcat "\nNext Number is: " (itoa MHNumber)))  
			  )
		     )
	        )
	    )
        )
     )
  )(princ)
 )

HTH

Message 13 of 19
Sea-Haven
in reply to: Anonymous

Sea-Haven
Mentor
Mentor

Noticed one thing should a direction be checked 1st is there a rule lowest number is at low point ? Some sewer authorities will insist on this.

0 Likes

Noticed one thing should a direction be checked 1st is there a rule lowest number is at low point ? Some sewer authorities will insist on this.

Message 14 of 19
Anonymous
in reply to: pbejse

Anonymous
Not applicable

I don't know how to thank you 
Thank you very much it's amazing, can I ask you for another small lisp to draw an arrow with the opposite direction of the manholes taking the same block arrow in this drawing  

0 Likes

I don't know how to thank you 
Thank you very much it's amazing, can I ask you for another small lisp to draw an arrow with the opposite direction of the manholes taking the same block arrow in this drawing  

Message 15 of 19
Anonymous
in reply to: Sea-Haven

Anonymous
Not applicable

"Rule lowest number is at low point" that is true when we design if it's a gravity network usually for sewer, we start from the inlet for treatment plant considering it our lowest point and the first manhole will be MH0/MH1
See this example DWG 
The magenta line is our main 
The green lines are sublines

0 Likes

"Rule lowest number is at low point" that is true when we design if it's a gravity network usually for sewer, we start from the inlet for treatment plant considering it our lowest point and the first manhole will be MH0/MH1
See this example DWG 
The magenta line is our main 
The green lines are sublines

Message 16 of 19
Sea-Haven
in reply to: Anonymous

Sea-Haven
Mentor
Mentor

Understand just mentioned if your auto labelling manholes need to check direction 1st.

 

Sewer and drainage https://civilsitedesign.com/

 

The software makes a network and does all labelling in one go.

 

0 Likes

Understand just mentioned if your auto labelling manholes need to check direction 1st.

 

Sewer and drainage https://civilsitedesign.com/

 

The software makes a network and does all labelling in one go.

 

Message 17 of 19
pbejse
in reply to: Anonymous

pbejse
Mentor
Mentor
Accepted solution

@Anonymous wrote:

.. can I ask you for another small lisp to draw an arrow with the opposite direction of the manholes taking the same block arrow in this drawing  


Here you go.

...
(foreach itm '(("SEWER NAME" 4)("S-LINE" 220) ("Sewer_Manh" 7)("Arrow" 7)) ..
------------------------------------------------------------
(if
  (and
    (vl-every '(lambda (bn) 
	(tblsearch "BLOCK" bn)) '("LINE NAME" "MANH" "ARR"))..
------------------------------------------------------------
(setvar 'clayer "Arrow")
(command "-insert"  "ARR" "non" mdpt "0.25" "0.25" (rtd ang))
...

HTH

 

Refer to attached lisp file [ mnum.lsp ]

 

0 Likes


@Anonymous wrote:

.. can I ask you for another small lisp to draw an arrow with the opposite direction of the manholes taking the same block arrow in this drawing  


Here you go.

...
(foreach itm '(("SEWER NAME" 4)("S-LINE" 220) ("Sewer_Manh" 7)("Arrow" 7)) ..
------------------------------------------------------------
(if
  (and
    (vl-every '(lambda (bn) 
	(tblsearch "BLOCK" bn)) '("LINE NAME" "MANH" "ARR"))..
------------------------------------------------------------
(setvar 'clayer "Arrow")
(command "-insert"  "ARR" "non" mdpt "0.25" "0.25" (rtd ang))
...

HTH

 

Refer to attached lisp file [ mnum.lsp ]

 

Message 18 of 19
marwah.izmeqna
in reply to: pbejse

marwah.izmeqna
Participant
Participant

Hi,

 

I found this Lisp (mnum) which is used to number the manholes and to label the sewer pipeline, but I don't know what to write at the command line.

I tried mnum, it asks about the value to start with<1>, and when I type 1 it stops working.

0 Likes

Hi,

 

I found this Lisp (mnum) which is used to number the manholes and to label the sewer pipeline, but I don't know what to write at the command line.

I tried mnum, it asks about the value to start with<1>, and when I type 1 it stops working.

Tags (1)
Message 19 of 19

Kent1Cooper
Consultant
Consultant

It's looking for the drawing to contain Block definition(s) of one or more of these names:

"LINE NAME" "MANH" "ARR"

Do you use those?  If not, find them in the code and change to the name(s) you use.

Kent Cooper, AIA
0 Likes

It's looking for the drawing to contain Block definition(s) of one or more of these names:

"LINE NAME" "MANH" "ARR"

Do you use those?  If not, find them in the code and change to the name(s) you use.

Kent Cooper, AIA

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report