Jump to content

Recommended Posts

Posted
11 minutes ago, rlx said:

didn't had time to post this until now so assumed dlanorh would have posted by now (and he didn't dissapoint haha)

haven't looked at his code but I have no doubt it works just fine.

 

I have a lot of free time  :shock::playing:  (in hospital at the moment :( but hopefully discharged on friday :celebrate:)

Posted (edited)

oh dear... hope nothing serious and you'll be soon better & back home!

 

Edited by rlx
  • Like 1
Posted

Many thanks. A re-occurrence (and hopefully last) of an old infection.

Posted

Working in civil as an example in CIV3d you have multiple pattern choices to get around the data format problem pick the correct one to be used.

 

E,N,Z

P,E,N,Z

P,E,N,Z,code

P,E,N,Z,code,note 

P,E,N

 

and so on.

Posted (edited)

well, I did some testing with all of these lisps and the results are interesting..

my test file consists of 8525 points and here are the results :

220s - my original lisp

90s - my lisp tweaked with some Jonathans advices

26s - dlanorh

11s - rlx

 

after seeing this one must appreciate code optimisation...thank you all again 

p.s.

I hope u get well dlanorh

Edited by Tomislav
  • Like 1
Posted

Yeah, get well soon sicco :sick:  , oh sorry I mean dlanorh 😄

 

Hadn't really tested my code and saw I missed to place the point note (the gray one)  🤫  so no wonder dlanorh code was a little slower. Not that I think adding it will make much difference in speed. I removed the initget and the decimal places from updated code below since I don't put them to use. But you can put'm back as you please... Anyways , think the little difference in speed is because of vanilla vs. visual lisp (entmake vs vlax-invoke).

 

So maybe mine was faster (but incomplete) , maybe dlanorh's was better after all 🐉

 

for what its worth , here's the updated code (which on my system only takes 2 or 3 seconds)


(defun c:plo ( / fn fp vars vals fonth inp data)
 
  (defun _init () (vl-load-com)
    (setq vars (list (cons 'cmdecho 0) (cons 'dimzin 0) (cons 'osmode 0) (cons 'pdmode 34))
          vals (mapcar '(lambda (x)(getvar (car x))) vars))
    (mapcar '(lambda (x)(setvar (car x) (cdr x))) vars)
  )
 
  (defun _exit ()
    ; using this would also reset pdmode
    ;(mapcar '(lambda (x y)(setvar (car x) y)) vars vals)
    (if fp (close fp))
  )
 
  (defun *error* (msg) (princ msg) (_exit) (princ))

  ;;; main body
  (_init)
  (cond
    ((not (setq fn (getfiled "Coordinate File" (getvar 'dwgprefix) "txt" 4)))
     (princ "\nNo coordinate file selected"))
    ((not (setq fp (open fn "r")))
     (princ "\nUnable to read from coordinate file"))
    (t
     (setq fonth (getreal "\nEnter text height: "))
     (setvar 'PDSIZE (/ fonth 2.0))
     (command "-style" "°Point text" "swisscl.ttf" fonth 1 "" "" "" )
     (check_layers)
     (while (setq inp (read-line fp))
       (setq data (SplitStr (vl-string-trim " ," inp) ","))(place_point data))
     (vl-cmdf "-layer" "off" "°Point3D" "")
    )
  )
  (vl-cmdf "_.zoom" "_e")
  (_exit)
  (princ)
)

; point-num , point-x , point-y, point-h , point-code, point-note (point-code & note not allways present)
; example data record : 6216,649349.322,5034388.831,94.145,48,25
(defun place_point ( data / point-num x y point-h point-code point-note)
  (mapcar '(lambda (name value)(set name value)) '(point-num x y point-h point-code point-note) data)
  (place_point_entity (list (atof x) (atof y)))
  (place_point_num (list (atof x) (atof y)) point-num)
  (place_point_h (list (atof x) (atof y)) point-h)
  (if point-code (place_point_code (list (atof x) (atof y)) point-code))
  (if point-note (place_point_note (list (atof x) (atof y)) point-note))
)

(defun place_point_entity (point)
  (entmakex (list (cons 0 "POINT") (cons 10 point) (cons 8 "°Point2D"))))

(defun place_point_num (point s / ip)
  (setq ip (polar point (* pi 0.45) (* fonth 0.5)))
  (entmakex (list (cons 0 "TEXT")(cons 1 s)(cons 8 "°Point NUM")
    (cons 10 ip) (cons 11 ip) (cons 40 fonth) (cons 72 0) (cons 73 2))))

(defun place_point_h (point s / ip)
  (setq ip (polar point (* pi -0.45) (* fonth 0.5)))
  (entmakex (list (cons 0 "TEXT")(cons 1 s)(cons 8 "°Point H")
    (cons 10 ip) (cons 11 ip) (cons 40 fonth)(cons 72 0) (cons 73 2))))

(defun place_point_code (point s / ip)
  (setq ip (polar point (* pi 0.55) (* fonth 0.5)))
  (entmakex (list (cons 0 "TEXT")(cons 1 s)(cons 8 "°Point CODE")
    (cons 10 ip) (cons 11 ip) (cons 40 fonth)(cons 72 2) (cons 73 2))))

(defun place_point_note (point s / ip)
  (setq ip (polar point (* pi 1.45) (* fonth 0.5)))
  (entmakex (list (cons 0 "TEXT")(cons 1 s)(cons 8 "°Point NOTE")
    (cons 10 ip) (cons 11 ip) (cons 40 fonth)(cons 72 2) (cons 73 2))))


(defun check_layers () (mapcar '(lambda (x) (create_layer (car x) (cadr x)))
  '(("°Point NUM" 3) ("°Point H" 2)("°Point CODE" 1)("°Point NOTE" 8)("°Point2D" 7)("°Point3D" 5))))

; n = name, c = color
(defun create_layer (n c) (if (and (snvalid n) (null (tblsearch "layer" n))) (entmake (list
  (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord")
    (cons 2 n) (cons 62 c) (cons 70 0) (cons 290 1)))))

;;; s = string d = delimiter p = position delimiter (thanx Lee Mac)
(defun SplitStr ( s d / p )
  (if (setq p (vl-string-search d s))(cons (substr s 1 p) (SplitStr (substr s (+ p 1 (strlen d))) d)) (list s)))

 

 

  • Like 1
Posted (edited)

now, I discovered that first lisp from Rlx isn't working properly :( 

I haven't noticed it cause I didn't zoom in to check assuming it's all right, but for some reason it isn't displaying h,code,note but only copying pt num to pt h and code..

I included test file and dwg

the second is good but it places numbers too close to a point..

p.s.

I really need that decimal places roundup

test file.txt

Edited by Tomislav
Posted

strange , cause it works on your first txt file ???

the format of your lines in the textfile is :

 

point-num , point-x , point-y, point-h , point-code, point-note (point-code & note not allways present)

example data record : 6216,649349.322,5034388.831,94.145,48,25

 

 

Posted (edited)
12 minutes ago, rlx said:

strange , cause it works on your first txt file ???

the format of your lines in the textfile is :

 

point-num , point-x , point-y, point-h , point-code, point-note (point-code & note not allways present)

example data record : 6216,649349.322,5034388.831,94.145,48,25

 

 

sometimes there's no point-num also , that's why I have that query 'do points have name'

Edited by Tomislav
Posted

ah I see... rounding of the numbers and placing only points with a name ... think that's no problem to fix. Biggest problem right now is I have to go home and my wife's sister is staying with us (hopefully not too long) So probably dlanorh's code isn't so bad after all 🤓 

Posted
1 hour ago, rlx said:

ah I see... rounding of the numbers and placing only points with a name ... think that's no problem to fix. Biggest problem right now is I have to go home and my wife's sister is staying with us (hopefully not too long) So probably dlanorh's code isn't so bad after all 🤓 

I hear you man...

I never said dlanor's code is bad, I think it's sophisticated...it's so advanced that I (so far you figured I'm not that great in lisp) can't figure what parts of it do, but I will persist in finding out..

 

once again thanx to you ALL!! 

Posted (edited)

@Tomislav

 

I've merged the lisps written by myself and @rlx into a new lisp. Please see attached. This uses @rlx entmake methods which should improve the speed.

plo2.lsp

Edited by dlanorh
  • Like 1
Posted

oh darn , now I don't have an excuse anymore NOT to spent more time with that hippie , thanx a lot dlanorh 😭

Posted
16 minutes ago, rlx said:

oh darn , now I don't have an excuse anymore NOT to spent more time with that hippie , thanx a lot dlanorh 😭

 

🤓 You shouldn't mock the afflicted. :P

Posted
8 minutes ago, dlanorh said:

 

🤓你不应该嘲笑受折磨的人。:P

I hope that your body will recover soon.

Posted
2 hours ago, dlanorh said:

@Tomislav

 

I've merged the lisps written by myself and @rlx into a new lisp. Please see attached. This uses @rlx entmake methods which should improve the speed.

plo2.lsp 3.91 kB · 1 download

 

 

it works like a charm except it doesn't round the coordinates of points for some reason, just text for height...

Posted
1 hour ago, Tomislav said:

 

 

it works like a charm except it doesn't round the coordinates of points for some reason, just text for height...

 

I didn't realise you wanted that, the previous one didn't either:oops:

 

Will sort it tomorrow.

Posted

in place of atof you could use 'datof'

 

 (defun datof (s i / n ) (if (and (= (type s) 'str) (numberp i) (setq n (vl-string-position (ascii ".") s))) (substr s 1 (+ 1 i n)) s)) 

 

test (datof "12345.67890" 2) where 2 is the number of decimals (dec  in your routine)

 

if data integrity is guaranteed :

(defun datof (s i) (substr s 1 (+ 1 i (vl-string-position (ascii ".") s))))

  • Like 2
Posted
1 hour ago, rlx said:

in place of atof you could use 'datof'

 

 


 (defun datof (s i / n ) (if (and (= (type s) 'str) (numberp i) (setq n (vl-string-position (ascii ".") s))) (substr s 1 (+ 1 i n)) s)) 

 

 

Congratulations, you've hit three figures :shock:

 

I was going to add this

 

;; based on Doug Broad's round Function
(defun rnd2dp ( val dp ) (setq dp (/ 1.0 (expt 10.0 (abs dp)))) (* dp (fix (/ ((if (minusp val) - +) val (* dp 0.5)) dp))))

and change this line to

 

(setq pt (mapcar '(lambda (x) (rnd2dp (atof x) dec)) (list (nth 0 t_lst) (nth 1 t_lst) (nth 2 t_lst)))

 

  • Like 1

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