Recent Posts

Pages: 1 [2] 3 4 ... 10
11
AutoLISP (Vanilla / Visual) / Re: Find the nest level of a list
« Last post by Grrr1337 on Today at 03:22:04 pm »
Wow Lee, you always keep up with this super-advanced lisp level!
Guess I still have to figure out the mapcar with a recursive function combo.

Ron, interesting technique, but here are some bad news:

Code - Auto/Visual Lisp: [Select]
  1. _$ (NestedListLevel '(((((("A")))((((((((((((((((((((((("B" ("C"))))))))))))))))))))))))("C")))) )
  2. 26
  3. _$ (NESTEDLISTLEVEL_RJP '(((((("A")))((((((((((((((((((((((("B" ("C"))))))))))))))))))))))))("C")))) )
  4. 30
  5. _$ (foo '(((((("A")))((((((((((((((((((((((("B" ("C"))))))))))))))))))))))))("C")))) )
  6. 26
12
AutoLISP (Vanilla / Visual) / Re: Find the nest level of a list
« Last post by Lee Mac on Today at 03:18:17 pm »
Code - Auto/Visual Lisp: [Select]
  1. (nestedlistlevel_rjp '(("(1") "2" "3"))

Code - Auto/Visual Lisp: [Select]
  1. (nestedlistlevel_rjp '(((1) (2) (3))))

:wink:
13
This might be of help.
I copied and modified this script. It allows you to select more than one block of the same name.

Type "BLS" to run the command.

Code: [Select]
;blockselect function
(defun bls (/ s blk bn opt selection )
(vl-load-com)
  (while (not
      (progn
        (initget "N")
        (setq blk (entsel "\nSelect Block/N for Block name:"))
        (cond
          ((null blk) (prompt "\n<<Null selection>>"))
          ((eq blk "N")
           (while (not
                    (and (Setq bn (getstring "\nEnter Block Name: "))
                         (tblsearch "Block" bn)
                    )
                  )
             (princ (Strcat "\n<< " bn " Invalid block name>>"))
             
           ) T
          )
          ((setq s (car blk))
           (if (eq (cdr (Assoc 0 (entget s))) "INSERT")
             (setq bn (vla-get-EffectiveName (vlax-ename->vla-object s)))
             (prompt "\n<<Invalid Object>>")
           )
          )
        )
      )
    )
  )
  (princ (Strcat "\nBlock Name Filter: " (Strcase BN)))
  (initget  "A W")
  (setq opt (cond ((getkword
                     (strcat "\n Choose option [Window/All] <Window>: ")
                   )
                  )
                  ("W")
            )
  )
  (setq selection
         (ssget (if (eq opt "A") "_X" "_:L")
                (list '(0 . "insert")
                      (cons 2 (strcat bn ",`*U*"))
                                      )
         )
  )
(sssetfirst nil selection)
  (princ)
  )
(defun c:bls()
  (bls)
  (princ)
  )

Quote
Quicker in what way? If it happens in the blink of an eye how do you know it quicker?
That's because I can see faster than the blinking of an eye ! 8-) That's a joke of course !

Quote
Welcome to the Swamp.

Thanks ! I was in the swamp before . For years ! Now that I came back , though , my account had been terminated . But that's no problem . And the truth is i remember you ; yes , with the cab picture ! Oh , by the way , is Keith Blackie still around ? I knew him long before coming to the Swamp ; although I can't remember the name of the previous glorious site  :-( .

Any way , as far as concerning the coding :
I didn't mean "faster" as far as concerning the time needed for the code to get executed . I was referring to the number of the lines . Of course what I thing of "faster" is personal ; there was no offense to David , who afterall kindly wrote down those codes .

I also tried to work it a little myself . I managed to find out that I can set the value of a property of an entinity (specifically here the Scale X , Y and Z factor of a Block object) by this :

( setq ObjectToChange ( ssget ":S" ) )
( setq PROPSsausage ( entget ( ssname ObjectToChange 0 ) ) )    ;(retrieve the sausage as it currently is)
( setq PROPSsausage ( subst ( cons 41 0.001 ) ( assoc 41 PROPSsausage) PROPSsausage) )  ;substitute the list with the new
( setq PROPSsausage ( subst ( cons 42 0.001 ) ( assoc 42 PROPSsausage) PROPSsausage) )  ;then for Scale Y
( setq PROPSsausage ( subst ( cons 43 0.001 ) ( assoc 43 PROPSsausage) PROPSsausage) )  ;then for Scale Z
( entmod PROPSsausage)

In which 41 is the characteristic number in the list of the property (for Scale X) and 0.001 is the new value .
Now all this made me happy for making me remember some of the old Lisp ! But soon I found out that this is not enough ! ... This code only works if you specifically select a single object ... But what about when there are a dozen of such blocks that need to be changed ? Well this is hard for me . Selecting them is easy (with SSget X) , but how will I set the value to each of the block ? I thing I'll have to somehow use the foreach function . And I see that David has already used it . So I'll try to see if I can adopt it to my own code . Afterall , that's why I like programing : it's like Mathematics ; you can do the same thing through various of ways !  :-) However , any suggestion will be welcomed !
14
Quote
Quicker in what way? If it happens in the blink of an eye how do you know it quicker?
That's because I can see faster than the blinking of an eye ! 8-) That's a joke of course !

Quote
Welcome to the Swamp.

Thanks ! I was in the swamp before . For years ! Now that I came back , though , my account had been terminated . But that's no problem . And the truth is i remember you ; yes , with the cab picture ! Oh , by the way , is Keith Blackie still around ? I knew him long before coming to the Swamp ; although I can't remember the name of the previous glorious site  :-( .

Any way , as far as concerning the coding :
I didn't mean "faster" as far as concerning the time needed for the code to get executed . I was referring to the number of the lines . Of course what I thing of "faster" is personal ; there was no offense to David , who afterall kindly wrote down those codes .

I also tried to work it a little myself . I managed to find out that I can set the value of a property of an entinity (specifically here the Scale X , Y and Z factor of a Block object) by this :

( setq ObjectToChange ( ssget ":S" ) )
( setq PROPSsausage ( entget ( ssname ObjectToChange 0 ) ) )    ;(retrieve the sausage as it currently is)
( setq PROPSsausage ( subst ( cons 41 0.001 ) ( assoc 41 PROPSsausage) PROPSsausage) )  ;substitute the list with the new
( setq PROPSsausage ( subst ( cons 42 0.001 ) ( assoc 42 PROPSsausage) PROPSsausage) )  ;then for Scale Y
( setq PROPSsausage ( subst ( cons 43 0.001 ) ( assoc 43 PROPSsausage) PROPSsausage) )  ;then for Scale Z
( entmod PROPSsausage)

In which 41 is the characteristic number in the list of the property (for Scale X) and 0.001 is the new value .
Now all this made me happy for making me remember some of the old Lisp ! But soon I found out that this is not enough ! ... This code only works if you specifically select a single object ... But what about when there are a dozen of such blocks that need to be changed ? Well this is hard for me . Selecting them is easy (with SSget X) , but how will I set the value to each of the block ? I thing I'll have to somehow use the foreach function . And I see that David has already used it . So I'll try to see if I can adopt it to my own code . Afterall , that's why I like programing : it's like Mathematics ; you can do the same thing through various of ways !  :-) However , any suggestion will be welcomed !

15
CAD General / Re: Poltergeist?
« Last post by Krushert on Today at 02:54:38 pm »
Someone else screwing with you in the office, or on a more serious note, someone else working in the project as well?
He said it was a Poltergeist.  Duhhhhh  :tongue2:
16
AutoLISP (Vanilla / Visual) / Re: Find the nest level of a list
« Last post by ronjonp on Today at 02:37:52 pm »
Here's mine:
Code - Auto/Visual Lisp: [Select]
  1. (defun nestedlistlevel_rjp (l)
  2.  (if (= (type l) 'list)
  3.    (apply 'max
  4.       (if (listp x)
  5. (length (vl-remove-if-not
  6.   (function (lambda (y) (= 40 y)))
  7.   (vl-string->list (vl-princ-to-string x))
  8. )
  9. )
  10. 0
  11.       )
  12.     )
  13.   )
  14.   l
  15.   )
  16.    )
  17.  )
  18. )
17
AutoLISP (Vanilla / Visual) / Re: Find the nest level of a list
« Last post by Lee Mac on Today at 02:01:47 pm »
Quick one:
Code - Auto/Visual Lisp: [Select]
  1. (defun foo ( lst )
  2.    (apply 'max (mapcar '(lambda ( x ) (if (listp x) (if (< 0 (vl-list-length x)) (+ 1 (foo x)) 1) 0)) lst))
  3. )
18
CAD General / Re: Poltergeist?
« Last post by Greg B on Today at 01:37:25 pm »
Someone else screwing with you in the office, or on a more serious note, someone else working in the project as well?
19
AutoLISP (Vanilla / Visual) / Find the nest level of a list
« Last post by Grrr1337 on Today at 01:31:53 pm »
Hey guys,
Anyone wanna play?  :idea:

The task is to find the "deepest" nesting level of a list:

Code - Auto/Visual Lisp: [Select]
  1. _$ (NestedListLevel "string") -> nil
  2. _$ (NestedListLevel nil ) -> nil
  3. _$ (NestedListLevel '("A" "B" "C") ) -> 0
  4. _$ (NestedListLevel '(("A")("B")("C")) ) -> 1
  5. _$ (NestedListLevel '(("A")(("B"))("C")) ) -> 2
  6. _$ (NestedListLevel '(("A")((((("B")))))("C")) ) -> 5
  7. _$ (NestedListLevel '(((("A")))((((((("B")))))))("C")) ) -> 7
  8. _$ (NestedListLevel '(((("A")))((((((((((((((((((((((("B" ("C"))))))))))))))))))))))))("C")) ) -> 24

I hope the above example is clear enough.  :rolleyes2:

Heres my attempt with this:
Code - Auto/Visual Lisp: [Select]
  1. ; _$ (NestedListLevel "string") -> nil
  2. ; _$ (NestedListLevel nil ) -> nil
  3. ; _$ (NestedListLevel '("A" "B" "C") ) -> 0
  4. ; _$ (NestedListLevel '(("A")("B")("C")) ) -> 1
  5. ; _$ (NestedListLevel '(("A")(("B"))("C")) ) -> 2
  6. ; _$ (NestedListLevel '(("A")((((("B")))))("C")) ) -> 5
  7. ; _$ (NestedListLevel '(((("A")))((((((("B")))))))("C")) ) -> 7
  8. ; _$ (NestedListLevel '(((("A")))((((((((((((((((((((((("B" ("C"))))))))))))))))))))))))("C")) ) -> 24
  9. (defun NestedListLevel ( L / rec )
  10.  (defun rec ( L i )
  11.    (or i (setq i 0))
  12.    (cond
  13.      ( (not L) (list i))
  14.      ( (and (listp L) (listp (car L))) (append (rec (car L) (1+ i)) (rec (cdr L) i)) )
  15.      ( (listp L) (rec (cdr L) i) )
  16.    )
  17.  )
  18.  (if (and L (listp L)) (apply 'max (rec L nil)) )
  19. ); defun NestedListLevel
IMO my code is a bit sloppy (sorry about that  - haven't done much recursions recently).
20
CAD General / Re: Poltergeist?
« Last post by Pepe on Today at 12:54:45 pm »
Hi ronjonp,

(CET time...) Today about 10:00h the file was Ok; about 12:30h began the mess...
Pages: 1 [2] 3 4 ... 10