Jump to content

Help me to combine my autolisp :(


Oktaradian

Recommended Posts

hi everyone, i have 2 different autolisp. I want to combine the two, but I'm too ordinary in terms of autolisp. can someone help me?

Quote

(defun c:test( / es ent str vtxlist c txtsize)
(defun make_TEXT (content textstyle layer color coo degree textsize / txt_list)
;;entmake text
 (if (null textstyle) (setq textstyle "standard"))
 (setq txt_list (list (cons 0 "TEXT") (cons 1 content) (cons 7 textstyle) (cons 8 layer) (cons 62 color) (cons 10 coo) (cons 50 degree) (cons 40 textsize)))  
 (entmake txt_list)
 (entlast)
)
(if (setq es (car (entsel "\nSelect Polyline >> ")))
 (progn
  (setq ent (entget es))
  (setq str "name");;;
  (setq vtxlist '())
  (mapcar '(lambda (x)
   (if (eq (car x) 10)
    (setq vtxlist (append vtxlist (list (cdr x))))
   )
           )
  ent);mapcar
  (setq c 1 txtsize 1)
  (foreach vtx vtxlist
   (make_text (strcat str (itoa c)) nil (getvar "clayer") 10 vtx 0 txtsize)
   (setq c (1+ c))
  )
 )
 (alert "CANCELED")
)
(princ)
)

Quote

(defun c:dcd (/ lstSS txtstr p1 p2 listname txt txt1 ss)
(vl-load-com)

(defun acet-ss-to-list (ss / n e l)
  (setq n (sslength ss))
  (while (setq e (ssname ss (setq n (1- n))))
    (setq l (cons e l))
  )
)

;Gan gia tri goc
(if (not k0) (setq k0 1));;gan gia tri goc
(setq k (getreal (strcat "\n Import Ratio of This drawing:1/" (rtos k0 2 0) "")));Nhap ty le ban ve
(if (not k) (setq k k0) (setq k0 k))  
(defun dowith(lstSS / lstSS en str)
(cond  ((setq en  (car (vl-remove-if-not '(lambda(x)(wcmatch (cdadr (entget x))"*TEXT")) lstSS)))(setq str (acet-dxf 1 (entget en)) en (vlax-ename->vla-object en)))
  ((setq en (car (vl-remove-if-not '(lambda(x)(and (wcmatch (cdadr (entget x))"INSERT")(= (acet-dxf 66 (entget x)) 1))) lstSS)))
   (setq str (vla-get-textstring (setq en(car (vlax-invoke (vlax-ename->vla-object en) 'GetAttributes)))))
  )
)
(cons en str)
)
(grtext -1 "Edit By Nguy\U+1EC5n Ng\U+1ECDc S\U+01A1n")
(setq  lstSS (acet-ss-to-list (setq ss (ssget)))
  obj (car (setq en (dowith lstSS)))
  str (cdr en)
  p1 (getpoint "\nOrigin Point:")
  eL (entlast)
 oDz (getvar "Dimzin")
)
(setvar "DIMZIN" 0)
(while (setq p2 (getpoint p1 "\nNext Point:"))
(command "copy" ss "" p1 p2)
(while (setq EL (entnext EL)) (setq Listname (cons EL Listname)))
(setq  Txt1 (car (dowith listName))
  eL (entlast)
)
(Ktra)
(setvar "cecolor" "bylayer")  
(vla-put-textstring txt1
(strcat (cond ((> (setq num (+ (atof str) (/ (- (cadr p2)(cadr p1)) k))) 0) "")
    ((= num 0) "%%p")
    (T "")
   )
(rtos num  2 3));So chu so dau dau ;
)
)
(setvar "DIMZIN" oDZ)
)
;Tim va tao moi Layer
(defun ktra ()
(if (not (tblsearch "layer" "Caodo"))
     (command "-LAYER" "m" "Caodo" "c" 1 "Caodo" "" )
     (setvar "clayer" "Caodo" )
)
)
 

I want the autolisp function like this: 

1. pick point datum

2. select polyline

3. and text elevations appears at each vertex point

20200116_222622.gif

Link to comment
Share on other sites

  • 1 month later...

As you can see, im too a newbie but you can combine 2 lisp.

Quote

(Defun test()

..codes

.)

Defun test2 ()

...codes

)

(Defun c:Sheep ()

(Test)

(Test2)

)

To run the combined lisp just type Sheep. The rest of your questions, somebody with deeper knowledge might jump in.

Link to comment
Share on other sites

(defun c:test ( / datum es hgts txt_color txt_height txt_layer txt_rotation txt_style vtxlist DegToRad)
  
  ;;; -------------------- SET TEXT PROPERTIES BELOW -------------------- ;;;
  
  (setq
    txt_height 10
    txt_style "standard"
    txt_layer "New Layer" ; or nil to use current layer
    txt_rotation 90	; in degrees
    txt_color acWhite ; or nil to use default color
    )
  
  ;;; -------------------- SET TEXT PROPERTIES ABOVE -------------------- ;;;
  
  (defun DegToRad (x) (* (/ pi 180) x))
  (while
    (progn
      (setq es (entsel "\nSelect Polyline >> "))
      (cond
	((not es) (princ "\nNothing selected"))
	((wcmatch (cdr (assoc 0 (entget (car es)))) "~*POLYLINE") (princ "\nObject is not a polyline"))
	)
      )
    )
  
  
  (setq datum (progn (initget 1) (getpoint "\nSpecify point for datum: "))
	elev (progn (initget 1) (getreal "\nSpecify elevation at specified datum: "))
	vtxlist (vl-remove-if-not '(lambda (x) (eq (car x) 10)) (entget (car es)))
	hgts (mapcar '(lambda (x) (+ elev (- (caddr x) (cadr datum)))) vtxlist)
	)
  
  (mapcar '(lambda (x y)
	     (entmake
	       (vl-remove nil
		 (list
		   '(0 . "TEXT")
		   (cons 7 (if (null (tblsearch "STYLE" txt_style)) "standard" txt_style))
		   (if txt_layer (cons 8 txt_layer))
		   (cons 10 (cdr x))
		   (cons 1 (rtos y))
		   (cons 50 (DegToRad txt_rotation))
		   (cons 40 txt_height)
		   (if txt_color (cons 62 txt_color))
		   )
		 )
	       )
	     )
	  vtxlist
	  hgts
	  )
  (princ)
  )

 

Edited by Jonathan Handojo
Link to comment
Share on other sites

thanks. I've tried it.
but not the distance value that I want. I tried to find the elevation value.
Can you help me?

test.png

Link to comment
Share on other sites

Oops, I initially thought the datum was set at 0, hence those values. I've amended the changes to the above code to allow you to input the elevation value at the specified point.

 

Try the above code again. If you specify the datum point at the 161, 163 or any mark and input that same value as the elevation height, you should get what you're after.

Edited by Jonathan Handojo
Link to comment
Share on other sites

sorry I don't really understand. I'm a beginner here. I already tried entering the datum value, but what appears is still the distance value not elevation

Link to comment
Share on other sites

HI

 Jonathan Handojo     AND   Oktaradian

 

Allow me to add the height   AT  Specify point for datum  

 

 

 

 

 

(defun c:test ( / datum es hgts txt_color txt_height txt_layer txt_rotation txt_style vtxlist DegToRad lev)
  
  ;;; -------------------- SET TEXT PROPERTIES BELOW -------------------- ;;;

  (setq
    txt_height 10
    txt_style "standard"
    txt_layer "New Layer"
    txt_rotation 90    ; in degrees
    txt_color nil ; or nil to use default color
    )

  ;;; -------------------- SET TEXT PROPERTIES ABOVE -------------------- ;;;

  (defun DegToRad (x) (* (/ pi 180) x))
  (while
    (progn
      (setq es (entsel "\nSelect Polyline >> "))
      (cond
    ((not es) (princ "\nNothing selected"))
    ((wcmatch (cdr (assoc 0 (entget (car es)))) "~*POLYLINE") (princ "\nObject is not a polyline"))
    )
      )
    )
  (setq lev (getdist "\n inter level Specify point for datum  :"))
  (initget 1)
  (setq datum (getpoint "\nSpecify point for datum: "))
(setq    vtxlist (vl-remove-if-not '(lambda (x) (eq (car x) 10)) (entget (car es))))
(setq    hgts (mapcar '(lambda (x) (+ lev (- (caddr x) (cadr datum)))) vtxlist))
    

  (mapcar '(lambda (x y)
         (entmake
           (vl-remove nil
         (list
           '(0 . "TEXT")
           (cons 7 (if (null (tblsearch "STYLE" txt_style)) "standard" txt_style))
           (cons 8 txt_layer)
           (cons 10 (cdr x))
           (cons 1 (rtos y))
           (cons 50 (DegToRad txt_rotation))
           (cons 40 txt_height)
           (if txt_color (cons 62 txt_color))
           )
         )
           )
         )
      vtxlist
      hgts
      )
  (princ)
  )

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Capture33.JPG

Link to comment
Share on other sites

image.thumb.png.2a41760bdf0f74ec6e6437121eb1c1af.png

 

The datum is there.

 

image.thumb.png.81cd2011eb49ba29d261574b1ef69f9e.png

 

The point at that datum is 100.

 

image.thumb.png.dd9aab0b66697f7a26b5c2d672ec605e.png

 

There's the result.

 

Perhaps the code wasn't updated:

 

(defun c:test ( / datum es hgts txt_color txt_height txt_layer txt_rotation txt_style vtxlist DegToRad)
  
  ;;; -------------------- SET TEXT PROPERTIES BELOW -------------------- ;;;
  
  (setq
    txt_height 10
    txt_style "standard"
    txt_layer "New Layer" ; or nil to use current layer
    txt_rotation 0	; in degrees
    txt_color acWhite ; or nil to use default color
    )
  
  ;;; -------------------- SET TEXT PROPERTIES ABOVE -------------------- ;;;
  
  (defun DegToRad (x) (* (/ pi 180) x))
  (while
    (progn
      (setq es (entsel "\nSelect Polyline >> "))
      (cond
	((not es) (princ "\nNothing selected"))
	((wcmatch (cdr (assoc 0 (entget (car es)))) "~*POLYLINE") (princ "\nObject is not a polyline"))
	)
      )
    )
  
  
  (setq datum (progn (initget 1) (getpoint "\nSpecify point for datum: "))
	elev (progn (initget 1) (getreal "\nSpecify elevation at specified datum: "))
	vtxlist (vl-remove-if-not '(lambda (x) (eq (car x) 10)) (entget (car es)))
	hgts (mapcar '(lambda (x) (+ elev (- (caddr x) (cadr datum)))) vtxlist)
	)
  
  (mapcar '(lambda (x y)
	     (entmake
	       (vl-remove nil
		 (list
		   '(0 . "TEXT")
		   (cons 7 (if (null (tblsearch "STYLE" txt_style)) "standard" txt_style))
		   (if txt_layer (cons 8 txt_layer))
		   (cons 10 (cdr x))
		   (cons 1 (rtos y))
		   (cons 50 (DegToRad txt_rotation))
		   (cons 40 txt_height)
		   (if txt_color (cons 62 txt_color))
		   )
		 )
	       )
	     )
	  vtxlist
	  hgts
	  )
  (princ)
  )

 

Edited by Jonathan Handojo
Link to comment
Share on other sites

Yea, exactly that. I updated the code at the previous post, but I guess it mustn't have been updated considering that your post above shows the earlier code before it was updated.

 

I simply modified the below snippet:

 

  (setq datum (progn (initget 1) (getpoint "\nSpecify point for datum: "))
	elev (progn (initget 1) (getreal "\nSpecify elevation at specified datum: "))
	vtxlist (vl-remove-if-not '(lambda (x) (eq (car x) 10)) (entget (car es)))
	hgts (mapcar '(lambda (x) (+ elev (- (caddr x) (cadr datum)))) vtxlist)
	)

Simply using (initget 1) to make sure that the user does really input a number and doesn't press enter in order to have getreal return nil.

And of course prompting the user for the elevation height for calculation

Edited by Jonathan Handojo
  • Thanks 1
Link to comment
Share on other sites

Just a hint for anyone you can read the text even if say RL100.5 and return its numeric value, thanks Lee-mac,  then pick the Y point for the datum so no need to actually manually enter the datum number. I have something similar coded. Also takes into account horizontal and vertical scale I did not see anything about that in code above.

 

(getreal "\nSpecify elevation at specified datum: "))

Link to comment
Share on other sites

1 hour ago, BIGAL said:

Just a hint for anyone you can read the text even if say RL100.5 and return its numeric value, thanks Lee-mac,  then pick the Y point for the datum so no need to actually manually enter the datum number. I have something similar coded. Also takes into account horizontal and vertical scale I did not see anything about that in code above.

 

(getreal "\nSpecify elevation at specified datum: "))

Hmm, it's a nice idea, just select the text and do (+ (car (LM:parsenumbers (cdr (assoc 1 (entget txt))))) (cadr datum)). Not bad.

 

Regarding scale, I presume that the graph is drawn to scale. Definitely can amend those in the code of anything.

Edited by Jonathan Handojo
Link to comment
Share on other sites

Just now, Jonathan Handojo said:

image.thumb.png.2a41760bdf0f74ec6e6437121eb1c1af.png

 

The datum is there.

 

image.thumb.png.81cd2011eb49ba29d261574b1ef69f9e.png

 

The point at that datum is 100.

 

image.thumb.png.dd9aab0b66697f7a26b5c2d672ec605e.png

 

There's the result.

 

Perhaps the code wasn't updated:

 


(defun c:test ( / datum es hgts txt_color txt_height txt_layer txt_rotation txt_style vtxlist DegToRad)
  
  ;;; -------------------- SET TEXT PROPERTIES BELOW -------------------- ;;;
  
  (setq
    txt_height 10
    txt_style "standard"
    txt_layer "New Layer" ; or nil to use current layer
    txt_rotation 0	; in degrees
    txt_color acWhite ; or nil to use default color
    )
  
  ;;; -------------------- SET TEXT PROPERTIES ABOVE -------------------- ;;;
  
  (defun DegToRad (x) (* (/ pi 180) x))
  (while
    (progn
      (setq es (entsel "\nSelect Polyline >> "))
      (cond
	((not es) (princ "\nNothing selected"))
	((wcmatch (cdr (assoc 0 (entget (car es)))) "~*POLYLINE") (princ "\nObject is not a polyline"))
	)
      )
    )
  
  
  (setq datum (progn (initget 1) (getpoint "\nSpecify point for datum: "))
	elev (progn (initget 1) (getreal "\nSpecify elevation at specified datum: "))
	vtxlist (vl-remove-if-not '(lambda (x) (eq (car x) 10)) (entget (car es)))
	hgts (mapcar '(lambda (x) (+ elev (- (caddr x) (cadr datum)))) vtxlist)
	)
  
  (mapcar '(lambda (x y)
	     (entmake
	       (vl-remove nil
		 (list
		   '(0 . "TEXT")
		   (cons 7 (if (null (tblsearch "STYLE" txt_style)) "standard" txt_style))
		   (if txt_layer (cons 8 txt_layer))
		   (cons 10 (cdr x))
		   (cons 1 (rtos y))
		   (cons 50 (DegToRad txt_rotation))
		   (cons 40 txt_height)
		   (if txt_color (cons 62 txt_color))
		   )
		 )
	       )
	     )
	  vtxlist
	  hgts
	  )
  (princ)
  )

 

 

Thank you very much. this is what i mean.
if only I could learn to make my own autolisp

🥰

Link to comment
Share on other sites

23 minutes ago, Oktaradian said:

 

Thank you very much. this is what i mean.
if only I could learn to make my own autolisp

🥰

Oh don't worry, I have miles to learn too. Glad it worked out.

Link to comment
Share on other sites

4 hours ago, Jonathan Handojo said:

Oh don't worry, I have miles to learn too. Glad it worked out.

 


GET ME ASK A QUESTION AGAIN ABOUT AUTOLISP? I HAVE A AUTOLISP TO PRINT PLOT IMAGES FAST. BUT THIS AUTOLISP IS ALMOST EXPIRED. I WANT TO MAKE THE SAME AUTOLISP, BUT I CAN'T EDIT THIS AUTOLISP

defund = PL1 (Trial).VLX

Link to comment
Share on other sites

16 hours ago, Jonathan Handojo said:

I can't see the LISP file either. Can you explain what you want in detail of send snapshots again

 

I have autolisp in .VLX format, not .LSP
but this autolisp trial version. I tried to look for a similar autolisp, but did not find it on google.
I like this autolisp because it's fast to print images.
You can try to find out how it works, you can download the file here
Can you help me make autolisp similar like that?

 

1.png

2.png

3.png

defund = PL1 (Trial).VLX

Link to comment
Share on other sites

If that really is a DCL dialog, that must be a damn ton... at least worth 700+ lines to get that kind of dialog. I can make it, but I don't have that kind of time, sorry.

Link to comment
Share on other sites

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