Author Topic: newbie question: COND limits?  (Read 9370 times)

0 Members and 1 Guest are viewing this topic.

CHulse

  • Swamp Rat
  • Posts: 504
Re: newbie question: COND limits?
« Reply #30 on: November 12, 2010, 07:24:04 PM »
I thought it'd be better to provide hints than to just give the complete code  :-)  But maybe some of my hints aren't too clear :-(

Believe me, I appreciate it. Hints are best (usually) as it actually helps me learn :)
The clarity issue is that I have been up since about 3am  :ugly: , not your hints
Cary Hulse
Urban Forestry Manager
Wetland Studies and Solutions

Civil 3D 2020 & 2023

CHulse

  • Swamp Rat
  • Posts: 504
Re: newbie question: COND limits?
« Reply #31 on: November 12, 2010, 07:25:00 PM »
Ok, but now I get this:

** Error: bad function: "BOTANICAL" **

Code: [Select]
(setq atlist (("ID" tnum)("BOTANICAL" species)("COMMON" common)("CULTIVAR" cultivar)("DBH" dbh)("CONDITION" condition)("UNIQUEID" unique)("STEMS" stem)))

(foreach att (vlax-invoke obj 'GetAttributes)
            (if (setq attval (cadr (assoc (strcase(vla-get-TagString att)) atlist)))
               (vla-put-TextString att attval)))
Cary Hulse
Urban Forestry Manager
Wetland Studies and Solutions

Civil 3D 2020 & 2023

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: newbie question: COND limits?
« Reply #32 on: November 12, 2010, 07:31:50 PM »
You are getting closer, well done  :-)

The problem is that the list needs to be constructed using the proper functions, as it cannot be taken as a literal.

To be taken as a literal, (i.e. not evaluated), an apostrophe must be used, but, in your case, you cannot use this method as you need to evaluate the variables within your list.

The error occurs because elements of your list are interpreted as function expressions, e.g.

Code: [Select]
("BOTANICAL" species)
Is attempting to evaluate "BOTANICAL" as a function, which, of course, it is not.

To construct the list, look into using the list function, (and cons function if you want to use a dotted pair)

CHulse

  • Swamp Rat
  • Posts: 504
Re: newbie question: COND limits?
« Reply #33 on: November 12, 2010, 07:44:38 PM »
ok, I think I have it now - a list of lists...

Code: [Select]
(setq atlist (list
        (list "ID" tnum)(list "BOTANICAL" species)(list "COMMON" common)(list "CULTIVAR" cultivar)(list "DBH" dbh)
        (list "CONDITION" condition)(list "UNIQUEID" unique)(list "STEMS" stem)))
But this seems messy - would there be a better/cleaner way?
Cary Hulse
Urban Forestry Manager
Wetland Studies and Solutions

Civil 3D 2020 & 2023

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: newbie question: COND limits?
« Reply #34 on: November 12, 2010, 07:47:52 PM »
Excellent - good job  :-)

Yes, it could be done with mapcar:

Code: [Select]
(setq atlist
  (mapcar 'list
   '("ID" "BOTANICAL" "COMMON" "CULTIVAR" "DBH" "CONDITION" "UNIQUEID" "STEMS")
    (list tnum species common cultivar dbh condition unique stem)
  )
)

There may be also a cleaner way to obtain your original variables, perhaps making the above even more concise. :-)

CHulse

  • Swamp Rat
  • Posts: 504
Re: newbie question: COND limits?
« Reply #35 on: November 12, 2010, 07:50:25 PM »
Cool. Asside from looking cleaner, would MAPCAR run faster? That is one I still have some trouble grasping...

Well, again, thanks for your help and hints. Much appreciated :)
I still need to drive 2 hours to get home, so have a good weekend.

Cary Hulse
Urban Forestry Manager
Wetland Studies and Solutions

Civil 3D 2020 & 2023

CHulse

  • Swamp Rat
  • Posts: 504
Re: newbie question: COND limits?
« Reply #36 on: November 12, 2010, 07:53:14 PM »
Using your STRBRK function, I have this:

Code: [Select]
(WHILE (setq line (CAR *lst*))

        (setq ;; method by FIXO @ CadTutor
          tnum (ATOF (nth 0 line))
          ;;common (nth 1 line)
          species (nth 1 line)
          cultivar (nth 2 line)
          dbh (atof (nth 3 line))
          condition (nth 4 line)
          x (atof (nth 5 line))
          y (ATOF (nth 6 line))
          unique (nth 7 line)
          stem (nth 8 line)
          crz (ATOF (nth 9 line))
          photo (nth 10 line)
         
        );_end of setq

to establish the vars from a csv file input.
Cary Hulse
Urban Forestry Manager
Wetland Studies and Solutions

Civil 3D 2020 & 2023

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: newbie question: COND limits?
« Reply #37 on: November 12, 2010, 07:56:04 PM »
Cool. Asside from looking cleaner, would MAPCAR run faster? That is one I still have some trouble grasping...

I doubt there would be much difference, perhaps mapcar may be slightly faster, but I would think the difference would be negligible.

As for understanding, here is a brief explanation I wrote a while back:

http://www.cadtutor.net/forum/showthread.php?52127-Mapcar-lambda-Description&p=353101&viewfull=1#post353101


Well, again, thanks for your help and hints. Much appreciated :)
I still need to drive 2 hours to get home, so have a good weekend.

You're welcome - have a good weekend yourself too  :-)

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: newbie question: COND limits?
« Reply #38 on: November 12, 2010, 07:59:41 PM »
Using your STRBRK function, I have this:

I can't give a complete answer, as I don't know how the variables are used elsewhere in the code, but, I would have thought that if you are dealing with attributes, you would want to deal in strings alone.

With that in mind, perhaps something similar to this may merge the two operations:

Code: [Select]
(while (setq line (car *lst*))
  (setq atlist (mapcar 'list '("ID" "BOTANICAL" ... ) line))
)

Lee

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: newbie question: COND limits?
« Reply #39 on: November 12, 2010, 08:10:08 PM »
Some more food for thought (apologies in advance: I did not read the entire thread, hope the following fits):

Code: [Select]
(setq vars '(tnum species cultivar dbh condition x y unique stem crz photo))

(while (setq line (car *lst*))

    (mapcar 'set vars line)
    
    ;; perform any additional variable refinement
    ;; I'm suggesting the distof function rather than atof    
    ;; however, I've not read the rest of the thread so its  
    ;; use may not necessarily be the most appropriate          
    ;; also note additional defensive coding may be applicable  
    ;; regardless distof or atof function usage                
    
    (mapcar
       '(lambda ( var ) (set var (distof (eval var))))
       '(tnum dbh x y crz)
    )
    
    ;;  carry on and do other stuff
    
    ;;  remember to modify the *lst* variable or you'll have an infinite loop
    
    (setq *lst* (cdr *lst))

)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: newbie question: COND limits?
« Reply #40 on: November 12, 2010, 08:18:10 PM »

Quote
.. additional defensive coding may be applicable

now, there's a concept that could fill a couple of chapters. !

:)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: newbie question: COND limits?
« Reply #41 on: November 12, 2010, 11:50:53 PM »
Another variation, for example only.
Code: [Select]
  (setq vars '("ID" "BOTANICAL" "COMMON" "CULTIVAR" "DBH" "CONDITION" "UNIQUEID" "STEMS"))

  (setq atlist
           (mapcar '(lambda (var)
                      (list var
                            (cond
                              ((vl-position var '("ID" "DBH" "STEMS"))
                               (distof (eval (read var))))
                              ((eval (read var)))
                             ))) vars)
  )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CHulse

  • Swamp Rat
  • Posts: 504
Re: newbie question: COND limits?
« Reply #42 on: November 14, 2010, 09:09:24 AM »
Using your STRBRK function, I have this:

I can't give a complete answer, as I don't know how the variables are used elsewhere in the code, but, I would have thought that if you are dealing with attributes, you would want to deal in strings alone.

With that in mind, perhaps something similar to this may merge the two operations:

Code: [Select]
(while (setq line (car *lst*))
  (setq atlist (mapcar 'list '("ID" "BOTANICAL" ... ) line))
)

Lee

After you mentioned MAPCAR, I thought of something liike that, but not all the vars are used to populate attribs, x and y are a point, some are dynamic functions and one is a path for the hyperlink.

Thanks to everyone  - plenty of "food for thot" (if you like Dr John)...
It works as is, but I will continue to refine it just to help me learn some other methods.
Cary Hulse
Urban Forestry Manager
Wetland Studies and Solutions

Civil 3D 2020 & 2023

CHulse

  • Swamp Rat
  • Posts: 504
Re: newbie question: COND limits?
« Reply #43 on: November 14, 2010, 09:25:45 AM »

Quote
.. additional defensive coding may be applicable

now, there's a concept that could fill a couple of chapters. !

:)

Ok, would someone like to explain this a bit more...? :)
Cary Hulse
Urban Forestry Manager
Wetland Studies and Solutions

Civil 3D 2020 & 2023

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: newbie question: COND limits?
« Reply #44 on: November 14, 2010, 09:29:53 AM »

Quote
.. additional defensive coding may be applicable

now, there's a concept that could fill a couple of chapters. !

:)

Ok, would someone like to explain this a bit more...? :)

Google is your friend  :-)

http://en.wikipedia.org/wiki/Defensive_programming