Search code examples
lispautocadautolisp

convert vlax-ename->vla-object of multiple objects


what I am trying to do is trying to convert multiple entities into VLA-OBJECTS in prder to use the Vlisp functions available for them. What I am trying to do is:

(while (<= masa masas)
    (set (read (strcat "off" (itoa masa) )) (cdr (assoc -1 (eval (read (strcat "offset" (itoa masa)))))))
    (set (read (strcat "obj" (itoa masa) )) (vlax-ename->vla-object (read (strcat "off" (itoa masa) ))))
    (setq masa (+ masa  1))
)

where masa is a counter that allows to go out of the while loop and masas is the variable limit. in wy code the first and the third line inside the while loop is working perfectly but the second one where I am trying to convert each ename into VLA object gives me the error bad argument type: lentityp OFF1 because in this case off starts in 1, I think the problem is not the uppercase result of read because lisp is not case-sensitive but rather than that a type problem that I can not solve. I also tried with eval or using directly assoc -1 but I have not been lucky.


Solution

  • The error message means OFF1 is not an ENAME (it's a symbol). You need to evaluate the symbol value with (eval ...).

    (while (<= masa masas)
      (set (read (strcat "off" (itoa masa)))
           (cdr (assoc -1 (eval (read (strcat "offset" (itoa masa))))))
      )
      (set (read (strcat "obj" (itoa masa)))
           (vlax-ename->vla-object (eval (read (strcat "off" (itoa masa)))))
      )
      (setq masa (1+ masa))
    )
    

    IMO, you should rather use lists, instead of assigning all these incremented variables. To use these variables, you'll need to loop through them with while or repeat as you could do with list and foreach. Assuming offsetList is the list of the dxf lists (all your offset(n) values), you can simply build a list of enameS and a list of vla-objectS.

    (setq offList (mapcar '(lambda (x) (cdr (assoc -1 x))) offsetList))
    (setq objList (mapcar 'vlax-ename->vla-object offList))