Johntosh Posted November 21, 2008 Posted November 21, 2008 I have umpteen points that I'm set to join-up with lines, my problem is finding the first one in the database (then I'll use the entnext function) My theory is to count up the points and then starting at an arbitrary point count the remainder (using script) and work my way back...long process! I should suppose it's a simpler matter of querying the database? Quote
devitg Posted November 21, 2008 Posted November 21, 2008 I have umpteen points that I'm set to join-up with lines, my problem is finding the first one in the database (then I'll use the entnext function) My theory is to count up the points and then starting at an arbitrary point count the remainder (using script) and work my way back...long process! I should suppose it's a simpler matter of querying the database? The first one, is the first made , you can get the order if you do an SSGET for such points , then loop with ssname , or convert the SS to a LIST , and with a foreach make the lines. If you can upload the dwg , it will be easy to help. Quote
Johntosh Posted November 21, 2008 Author Posted November 21, 2008 Thanks for your response I was just contemplating if ssget puts them in order but it makes sense that it will collect them in order anyway. I can'tupload this drawing but I will do that more on these forums. Thanks again. Quote
wizman Posted November 21, 2008 Posted November 21, 2008 (entnext) returns the name of the first entity in the database (entnext en) returns the name of the next entity after the entity identified by the variable en. Quote
devitg Posted November 21, 2008 Posted November 21, 2008 (entnext) returns the name of the first entity in the database (entnext en) returns the name of the next entity after the entity identified by the variable en. As Johntosh said, it have POINT's to dig on, so he need to get first such point , and not any other enty. Quote
wizman Posted November 21, 2008 Posted November 21, 2008 (ssname myset 0) ... you can get it through this: (defun c:entfirst () (Setq ent_dbase (ssget '((0 . "POINT")))) (setq ent_1st (entnext)) (setq ent_x (entnext ent_1st)) (While (not (vl-some '(lambda (x) (equal x ent_x) ) ;_ end_lambda (vl-remove-if 'listp (mapcar 'cadr (ssnamex ent_dbase) ) ;_ end_mapcar ) ;_ end_vl-remove-if ) ;_ end_vl-some ) ;_ end_not (setq ent_x (entnext ent_x)) ) ;_ end_While (redraw ent_x 3) ent_x ) ;_ end_defun Quote
CAB Posted November 21, 2008 Posted November 21, 2008 Another play toy. (defun c:test (/ ent elst result pt pend) (setq ent (entnext)) (while (setq ent (entnext ent)) (setq elst (entget ent)) (if (and (equal (assoc 0 elst) '(0 . "POINT")) (equal (assoc 410 elst) '(410 . "Model")) ) (setq result (cons (cdr(assoc 10 elst)) result)) ) ) (foreach pt (reverse result) (cond ((null pend) (setq pend pt)) (t (entmakex (list (cons 0 "LINE") ;;(cons 6 "BYLAYER") (cons 8 "0") (cons 10 pt) (cons 11 pend) ;;(cons 39 0.0) (cons 62 256) (cons 210 (list 0.0 0.0 1.0)) ) ) (setq pend pt) ) ) ) (princ) ) Quote
wizman Posted November 21, 2008 Posted November 21, 2008 (setq pend pt) i like calling this jumping variables, nice one alan.....:-) Quote
Johntosh Posted November 22, 2008 Author Posted November 22, 2008 That's some nifty coding, wizman. Helped me out a lot. Quote
Johntosh Posted November 22, 2008 Author Posted November 22, 2008 Thanks CAB, that's scripting I can get my head round right now. Quote
CAB Posted November 22, 2008 Posted November 22, 2008 You may also find this of interest. (defun c:PointSort (/ ss lst) (if (and (Setq ss (ssget '((0 . "POINT")))) ;; sort based on HANDLES (setq lst (mapcar 'entget (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))) ; to list of elist (setq lst (mapcar '(lambda (x) (nth x lst)) (vl-sort-i lst (function (lambda (e1 e2) (< (cdr (assoc 5 e1)) (cdr (assoc 5 e2)))))) ) ) ) (mapcar '(lambda(x) (cdr(assoc -1 x))) lst) ) ) Quote
wizman Posted November 22, 2008 Posted November 22, 2008 sort based on HANDLES thanks for sharing. -wiz Quote
VovKa Posted November 22, 2008 Posted November 22, 2008 CAB, there would be a problem sorting entities like this because ( as for me, i'd rather use something like this (defun entfirst1 (SS / EntName) (setq EntName (entnext)) (while (and (not (ssmemb EntName SS)) (setq EntName (entnext EntName))) ) EntName ) hope it will be the fastest one on small drawings Quote
devitg Posted November 22, 2008 Posted November 22, 2008 I got it from no known where , it is not mine. ;;*********************************************************************** (defun baseToDecimal (base val / pos power result tmp) (setq pos (1+ (strlen val)) power -1 result 0 val (strcase val) ) (while (> (setq pos (1- pos)) 0) (setq result (+ result (* (if (> (setq tmp (ascii (substr val pos 1))) 64) (- tmp 55) (- tmp 48) ) (expt base (setq power (1+ power))) ) ) ) ) result ) ;;*********************************************************************** (defun str-remove(str pos n / ) (strcat (substr str 1(1- pos)) (substr str(+ pos n)) ) ) ;;*********************************************************************** (setq val (vla-get-handle (vlax-ename->vla-object (car (entsel))))) (setq dec (baseToDecimal 16 val)) Quote
CAB Posted November 22, 2008 Posted November 22, 2008 Good catch VovKa. The goal is to sort the selection set by creation order. Quote
devitg Posted November 23, 2008 Posted November 23, 2008 Hi CAB , as my first post : (SSGET "X" ) is ordered or SORTED as they where made, so it´s handle is in order too Please see the following lisp , and the DWG where I applied I made each text in the order as numbered , b1 b2 b3 ...... c7 c8 . If the SSGET is made by hand , it will give the selection set , in the order they where picked , then a sorting defun by it´s handle will return the order they where made. ;;************************************************************************************************ (defun sort-<-y (lst) (vl-sort lst '(lambda (x y) (< (cadr x) (cadr y)))) ) ;;************************************************************************************************ ;;;/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/ (defun baseToDecimal (base val / pos power result tmp) (setq pos (1+ (strlen val)) power -1 result 0 val (strcase val) ) (while (> (setq pos (1- pos)) 0) (setq result (+ result (* (if (> (setq tmp (ascii (substr val pos 1))) 64) (- tmp 55) (- tmp 48) ) (expt base (setq power (1+ power))) ) ) ) ) result ) ;;;Purpose ;;;Returns an integer representing the value of a string converted from the numeric ;;;system indicated by BASE ;;; ;;;Arguments ;;;A string to convert and an integer indicating which system to convert from (base2, base8, etc.) ;;; ;;;Example ;;;(baseToDecimal 16 "FA") ;;; ;;/------------------------------------------------------------------ (defun ss->ent-list (ss / ) (mapcar 'cadr (ssnamex ss)) ) ;;************************************************************************************************************ (defun hex-dec-txt (ss-list / HANDLE-DEC HANDLE-HEX HEX-DEC-TEXT HEX-DEC-TEXT-LST TEXT$ ) (Setq hex-dec-text-lst nil) (foreach ent ss-list (setq handle-hex (cdr (assoc 5 (entget ent)))) (setq handle-dec (baseToDecimal 16 handle-hex)) (setq text$ (cdr (assoc 1 (entget ent)))) (setq hex-dec-text (list handle-hex handle-dec text$)) (setq hex-dec-text-lst (cons hex-dec-text hex-dec-text-lst)) ) ;_ foreach (reverse hex-dec-text-lst) ) ;;************************************************************************************************************ (defun by-ssget[x] (/ ALL SS[X]-LIST ) (setq all (ssget "X" '( ( 0 . "TEXT")))) (setq ss[x]-list (reverse(ss->ent-list all))) ( hex-dec-txt ss[x]-list) );_ defun ;;************************************************************************************************************ (defun by-ssget-random (/ SS-RANDOM SS-RANDOM-LIST ) (setq ss-random (ssget)) (setq ss-random-list (reverse ( ss->ent-list ss-random))) (sort-<-y( hex-dec-txt ss-random-list)) ) ;;************************************************************************************************************ (by-ssget-random) ;;;("200" 512 "b1") ;;;("201" 513 "b2") ;;;("202" 514 "b3") ;;;("203" 515 "b4") ;;;("204" 516 "b6") ;;;("205" 517 "b7") ;;;("206" 518 "b9") ;;;("207" 519 "b10") ;;;("208" 520 "c1") ;;;("209" 521 "c2") ;;;("20A" 522 "c3") ;;;("20B" 523 "c4") ;;;("20C" 524 "c5") ;;;("20D" 525 "c6") ;;;("20E" 526 "c7") ;;;("20F" 527 "c8") ;;; (by-ssget[x]) ;;;("200" 512 "b1") ;;;("201" 513 "b2") ;;;("202" 514 "b3") ;;;("203" 515 "b4") ;;;("204" 516 "b6") ;;;("205" 517 "b7") ;;;("206" 518 "b9") ;;;("207" 519 "b10") ;;;("208" 520 "c1") ;;;("209" 521 "c2") ;;;("20A" 522 "c3") ;;;("20B" 523 "c4") ;;;("20C" 524 "c5") ;;;("20D" 525 "c6") ;;;("20E" 526 "c7") ;;;("20F" 527 "c8") geting the order.dwg Quote
CAB Posted November 23, 2008 Posted November 23, 2008 Good job Devitg, my comment was directed at VovKa although it may not have been obvious. Your routine seems to work as desired. Just for grins here are my Hex routines: ;; CAB 09.11.08 ;; Convert Hexadecimal string to integer (defun Hex2Dec (str / n) (if (zerop (setq n (strlen str))) 0 (+ (* (cond ((< "@" (setq let (strcase (substr str 1 1))) "G")(- (ascii let) 55)) ((< "/" (setq let (strcase (substr str 1 1))) ":")(atoi let)) ) (expt 16 (1- n))) (Hex2Dec (substr str 2)) ) ) ) ;; CAB 09.11.08 ;; Convert integer to Hexadecimal string (defun Dec2Hex (num / str r) (setq str "") (while (progn (setq r (rem num 16.)) (cond ((< r 10) (setq str (strcat (itoa (fix r)) str))) ((< r 16) (setq str (strcat (chr (+ (fix r) 55)) str))) ) (> (setq num (fix (/ num 16.))) 0) ) ) str ) Quote
VovKa Posted November 23, 2008 Posted November 23, 2008 just to widen the variety (defun vk_Hex2Dec (Hex / Char Dec) (setq Hex (vl-string->list (strcase Hex)) Dec 0 ) (while (setq Char (car Hex)) (setq Hex (cdr Hex) Dec (+ Dec (* (- Char (if (<= 48 Char 57) 48 (if (<= 65 Char 70) 55 ) ) ) (expt 16 (length Hex)) ) ) ) ) Dec ) Quote
Recommended Posts
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.