Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Autolisp: unstable function

4 REPLIES 4
Reply
Message 1 of 5
Shinigami_black
292 Views, 4 Replies

Autolisp: unstable function

Hi,

I have made same autolisp routine, but one function same times return deferent results on the same input.

This this a function:

(defun GetBlockName (coordinatesList pointList / blockNameList x y ent entname blockName)
    (setq blockNameList (list))
    (while (and (setq x (car coordinatesList)) (setq y (cadr coordinatesList)))
        (setq point (car pointList))
        (setq ent (ssget "_C" (list (- x 0.5) (- y 0.5)) (list (+ x 0.5) (+ y 0.5)) '((2 . "PIKETAS"))))
        (if (= ent nil)
            (progn
                (setq ent (ssget "_C" (list (- x 0.5) (- y 0.5)) (list (+ x 0.5) (+ y 0.5)) '((2 . "Grezinys"))))
                (if (= ent nil)
                    (setq blockNameList (append (list (list (list "Nerasta") (list x y) point)) blockNameList))
                    (progn
                        (setq blockName (FindBlockAttribute ent "NR"))
                        (setq blockNameList (append (list (list (list blockName) (list x y) point)) blockNameList))
                    )
                )
            )
            (progn
                (setq blockName (FindBlockAttribute ent "NUMERIS"))
                (setq blockNameList (append (list (list (list blockName) (list x y) point)) blockNameList))
            )
        )
        (setq ent nil)
        (setq coordinatesList (cddr coordinatesList))
        (setq pointList (cdr pointList))
    )
    (reverse blockNameList)
)

 results of function run two times on same data:

blockNameList((("Nerasta") (431460.0 6.03049e+006) (432336.0 6.03032e+006)) (("Nerasta") (431463.0 6.03049e+006) (432330.0 6.03034e+006)) (("Nerasta") (431505.0 6.03044e+006) (432267.0 6.03036e+006)) (("Nerasta") (431517.0 6.0304e+006) (432227.0 6.03039e+006)) (("Nerasta") (431552.0 6.03037e+006) (432175.0 6.03043e+006)) (("47_84") (431570.0 6.03033e+006) (432136.0 6.03047e+006)) (("13_00") (431557.0 6.03028e+006) (432078.0 6.03046e+006)) (("2_00") (431506.0 6.03021e+006) (431995.0 6.03042e+006)) (("33_84") (431503.0 6.03015e+006) (431935.0 6.03037e+006)) (("9_00") (431450.0 6.03007e+006) (431837.0 6.03019e+006)) (("5") (431391.0 6.02999e+006) (431741.0 6.03021e+006)) (("Nerasta") (431387.0 6.02999e+006) (431733.0 6.03019e+006)))

blockNameList((("Nerasta") (431460.0 6.03049e+006) (432416.0 6.03039e+006)) (("17_00") (431463.0 6.03049e+006) (432410.0 6.03041e+006)) (("7") (431505.0 6.03044e+006) (432347.0 6.03043e+006)) (("14_00") (431517.0 6.0304e+006) (432307.0 6.03047e+006)) (("8") (431552.0 6.03037e+006) (432255.0 6.0305e+006)) (("47_84") (431570.0 6.03033e+006) (432216.0 6.03055e+006)) (("13_00") (431557.0 6.03028e+006) (432158.0 6.03054e+006)) (("2_00") (431506.0 6.03021e+006) (432075.0 6.0305e+006)) (("33_84") (431503.0 6.03015e+006) (432015.0 6.03044e+006)) (("9_00") (431450.0 6.03007e+006) (431917.0 6.03027e+006)) (("5") (431391.0 6.02999e+006) (431821.0 6.03028e+006)) (("Nerasta") (431387.0 6.02999e+006) (431814.0 6.03027e+006)))

 blockNameList consisting of input data and additional data.

("Nerasta") - this is additional data.

(431460.0 6.03049e+006) - data from coordinatesList

(432336.0 6.03032e+006) - data from pointList

 

pointList is not used in any calculations in this function, so it is uninportant. Only coordinateList is used for finding additional data. But I don't get why giving the same coordinates I get different results.

4 REPLIES 4
Message 2 of 5
Jeff_M
in reply to: Shinigami_black

Hi, You will undoubtedly get more repsonse to this if you move it over to the plain Autocad Lisp Customization forum where there are lots of lisp gurus. Have you stepped through the code in the VLIDE to watch what it is doing differently?

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 5
Shinigami_black
in reply to: Jeff_M

Hi,

how do I move this topic to AutoCAD Lisp forum? Does here are special move function, or do I need to create new topic in Lisp forum and dellete this topic?

 

I was stepping through my lisp routine to find this function, but did not had more time to go deeper in. Because wrong result don't came always. Same times you need a lot of trials. So it takes time to stepp through it, But I guess it must be (ssget) function.

Message 4 of 5
Jeff_M
in reply to: Shinigami_black

I've asked the moderator to move the thread for you.

 

Sometimes the only way to see why something is not working as expected is to step through it.

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 5
Shinigami_black
in reply to: Jeff_M

I was going through code in VLIDE and found out that problem are in this line

 

(setq ent (ssget "_C" (list (- x 0.5) (- y 0.5)) (list (+ x 0.5) (+ y 0.5)) '((2 . "PIKETAS"))))

 Some times it will return nil even if all are given the same as last time. I went through code several times and had found it will start to return nil randomly, but if you slow down it will return selection set.

 

I had put breakpoint near this funktion and was going through it fast by presing Crtl + F8, when it started to return nil, I slowed down and started to get selection sets and not nil.

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report