Author Topic: Variant To Object  (Read 1705 times)

0 Members and 1 Guest are viewing this topic.

abe123456789

  • Newt
  • Posts: 24
Variant To Object
« on: October 07, 2022, 05:33:01 PM »
Good afternoon,

When I use Vla-offset on a line I get a variant. How can I turn the new offset line into a object instead of a variant?

Thank you in advance.

Abe

hmspe

  • Bull Frog
  • Posts: 362
Re: Variant To Object
« Reply #1 on: October 07, 2022, 06:02:54 PM »
I use this approach:

          (vla-offset pline_object offset)
          (vla-delete pline_object)
          (setq pline (entlast))
          (setq pline_object (vlax-ename->vla-object pline))
"Science is the belief in the ignorance of experts." - Richard Feynman

mhupp

  • Bull Frog
  • Posts: 250
Re: Variant To Object
« Reply #2 on: October 07, 2022, 06:11:43 PM »
Guess your using something like this?

Code - Auto/Visual Lisp: [Select]
  1. (setq newline (vla-offset vla-objectname 10)) ;newline = variant :(

What I do is this
Code - Auto/Visual Lisp: [Select]
  1. (vla-offset vla-objectname 10)  ;strip the setq
  2. (setq newline (entlast))  ;use entlast to set entname
  3. (setq newline (vlax-ename->vla-object (entlast))  ;or vla-object name

or the long way around
Code - Auto/Visual Lisp: [Select]
  1. (setq newline (vlax-safearray->list (vlax-variant-value (vla-offset vla-objectname 10))))


 

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Variant To Object
« Reply #3 on: October 08, 2022, 02:29:53 AM »
Hi,
Because offseting some curves may generate more than one curve, the Offset method returns a variant which is an array of objects.
To get a more LISP friendly return value, we can convert this variant into a list:
Code - Auto/Visual Lisp: [Select]
  1. (vlax-safearray->list (vlax-variant-value (vla-offset line offsetValue)))
If you are absolutely sure that offseting the object will generate a single object (i.e. a line, an arc, a circle, ...), simply get the 'car' of this list.
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Variant To Object
« Reply #4 on: October 08, 2022, 10:01:58 AM »
A more generic one (from AutomationHelpers at the bottom of this page).
Code - Auto/Visual Lisp: [Select]
  1. ;; gc:VariantToLispData
  2. ;; Converts a variant or a safearry into an AutoLISP data
  3. ;;
  4. ;; Argument
  5. ;; var : variant or safearray
  6.  
  7. (defun gc:VariantToLispData (var)
  8.   (cond
  9.     ((= (type var) 'variant)
  10.      (gc:VariantToLispData (vlax-variant-value var)))
  11.     ((= (type var) 'safearray)
  12.      (if (< -1 (vlax-safearray-get-u-bound var 1))
  13.        (mapcar 'gc:VariantToLispData (vlax-safearray->list var))
  14.      )
  15.     )
  16.     (T var)
  17.   )
  18. )
Speaking English as a French Frog

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Variant To Object
« Reply #5 on: October 10, 2022, 12:10:34 PM »
Good afternoon,

When I use Vla-offset on a line I get a variant. How can I turn the new offset line into a object instead of a variant?

Thank you in advance.

Abe
You can also use VLAX-INVOKE to return a list of objects:
Code - Auto/Visual Lisp: [Select]
  1. (if (setq e (car (entsel)))
  2.   (vlax-invoke (vlax-ename->vla-object e) 'offset 1)
  3. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

abe123456789

  • Newt
  • Posts: 24
Re: Variant To Object
« Reply #6 on: October 10, 2022, 04:37:42 PM »
That answers my question.

Thanks for the help :-D