Author Topic: How can I check if the point type is a variant or not?  (Read 3790 times)

0 Members and 1 Guest are viewing this topic.

donnieworld

  • Newt
  • Posts: 26
  • BricsCAD Fan
How can I check if the point type is a variant or not?
« on: February 02, 2016, 12:18:03 AM »
 How can I check if the point type is a variant or not?

Some functions are setting the variable like:
(setq ptIns (getpoint "\nInsertion point > "))

others this way:
(setq ptIns (vla-getpoint util nil "\nInsertion point > "))

I need this function to identify the type:
(if (= ptIns ?is a variant?)
  (vlax-put-property myMText 'InsertionPoint ptIns)
  (vlax-put-property myMText 'InsertionPoint (vlax-3d-point ptIns))
)
Donald Broussard
Fusion Engineering and Technology

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2135
  • class keyThumper<T>:ILazy<T>
Re: How can I check if the point type is a variant or not?
« Reply #1 on: February 02, 2016, 12:41:17 AM »
Have a look at

https://www.bricsys.com/bricscad/help/en_AU/CurVer/DevRef/source/vlevariantp.htm

(vle-variantp  obj)

replacement for AutoCAD's : (= (type obj) 'VARIANT)
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How can I check if the point type is a variant or not?
« Reply #2 on: February 02, 2016, 04:30:42 AM »
Keep in mind that if you are writing Lisp code for BricsCAD you do no need to check this.

Code: [Select]
(setq myMText (vlax-ename->vla-object (car (entsel))))
(setq ptList '(0.0 0.0 0.0))
(setq ptVariant (vlax-3d-point '(1.0 1.0 1.0)))

This all works in BricsCAD:
Code: [Select]
(vla-put-insertionpoint myMText ptList)
(vla-put-insertionpoint myMText ptVariant)
(vlax-put-property myMText 'insertionpoint ptList)
(vlax-put-property myMText 'insertionpoint ptVariant)
(vlax-put myMText 'insertionpoint ptList)
(vlax-put myMText 'insertionpoint ptVariant)

donnieworld

  • Newt
  • Posts: 26
  • BricsCAD Fan
Re: How can I check if the point type is a variant or not?
« Reply #3 on: February 02, 2016, 10:42:02 AM »
Thanks, this is exactly what I was looking for. While BricsCAD is my primary target, all of my routines still need to run on AutoCAD as well. A couple, not this one, require that I have distinct code for each.

This is the complete function I am updating at the moment:

(defun HASD:AddMText ( ptIns nHt nRot sStyle sText sJust / )

   (cond
      ((= sJust "TL") (setq sJustify acAttachmentPointTopLeft))
      ((= sJust "TC") (setq sJustify acAttachmentPointTopCenter))
      ((= sJust "TR") (setq sJustify acAttachmentPointTopRight))
      ((= sJust "ML") (setq sJustify acAttachmentPointMiddleLeft))
      ((= sJust "MC") (setq sJustify acAttachmentPointMiddleCenter))
      ((= sJust "MR") (setq sJustify acAttachmentPointMiddleRight))
      ((= sJust "BL") (setq sJustify acAttachmentPointBottomLeft))
      ((= sJust "BC") (setq sJustify acAttachmentPointBottomCenter))
      ((= sJust "BR") (setq sJustify acAttachmentPointBottomRight))
      (t (setq sJustify acAttachmentPointMiddleCenter))
   )

   (setq nTextWidth 0) ; width of Mtext object still needs to be calculated

   (vla-SetVariable thisdrawing "TEXTSIZE" nHT)
   
   (setq myMText (vla-AddMText mspace (vlax-3d-point ptIns) nTextWidth sText))
      
   (if (= (vlax-property-available-p myMText 'AttachmentPoint) T)
      (vlax-put-property myMText 'AttachmentPoint sJustify))
   
   (if (= (vlax-property-available-p myMText 'Rotation) T)
      (vlax-put-property myMText 'Rotation (HASD:D2R nRot)))

   (if (= (vlax-property-available-p myMText 'StyleName) T)
      (vlax-put-property myMText 'StyleName sStyle))   
         
   (if (= (vlax-property-available-p myMText 'InsertionPoint) T)
      (vlax-put-property myMText 'InsertionPoint (vlax-3d-point ptIns)))
      
(princ)

)
Donald Broussard
Fusion Engineering and Technology

ronjonp

  • Needs a day job
  • Posts: 7528
Re: How can I check if the point type is a variant or not?
« Reply #4 on: February 02, 2016, 11:05:53 AM »
FWIW .. here's an idea for your justification code:

Code - Auto/Visual Lisp: [Select]
  1. (setq o (vlax-ename->vla-object (car (entsel))))
  2. (setq just "BR")
  3.           'attachmentpoint
  4.           (cdr (assoc just
  5.                       '(("TL" . 1)
  6.                         ("TC" . 2)
  7.                         ("TR" . 3)
  8.                         ("ML" . 4)
  9.                         ("MC" . 5)
  10.                         ("MR" . 6)
  11.                         ("BL" . 7)
  12.                         ("BC" . 8)
  13.                         ("BR" . 9)
  14.                        )
  15.                )
  16.           )
  17. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: How can I check if the point type is a variant or not?
« Reply #5 on: February 02, 2016, 12:24:15 PM »
Also:
Code - Auto/Visual Lisp: [Select]
  1. (setq o (vlax-ename->vla-object (car (entsel))))
  2. (setq just "BR")
  3. (vlax-put o 'attachmentpoint
  4.     (vl-position just '("""TL""TC""TR""ML""MC""MR""BL""BC""BR"))
  5. )

ronjonp

  • Needs a day job
  • Posts: 7528
Re: How can I check if the point type is a variant or not?
« Reply #6 on: February 02, 2016, 12:28:41 PM »
Cool :) .. did not know you could feed it strings too.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: How can I check if the point type is a variant or not?
« Reply #7 on: February 02, 2016, 12:35:52 PM »
Cool :) .. did not know you could feed it strings too.

Still using integers  :wink:

ronjonp

  • Needs a day job
  • Posts: 7528
Re: How can I check if the point type is a variant or not?
« Reply #8 on: February 02, 2016, 12:43:24 PM »
Cool :) .. did not know you could feed it strings too.

Still using integers  ;)

Well don't I feel silly  :oops:
LOL .. trickster you are  ;D  .. better finish my cup of coffee.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: How can I check if the point type is a variant or not?
« Reply #9 on: February 02, 2016, 12:44:37 PM »
 :-)

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: How can I check if the point type is a variant or not?
« Reply #10 on: February 02, 2016, 12:49:30 PM »
   (if (= (vlax-property-available-p myMText 'AttachmentPoint) T)
      (vlax-put-property myMText 'AttachmentPoint sJustify))
   
   (if (= (vlax-property-available-p myMText 'Rotation) T)
      (vlax-put-property myMText 'Rotation (HASD:D2R nRot)))

   (if (= (vlax-property-available-p myMText 'StyleName) T)
      (vlax-put-property myMText 'StyleName sStyle))   
         
   (if (= (vlax-property-available-p myMText 'InsertionPoint) T)
      (vlax-put-property myMText 'InsertionPoint (vlax-3d-point ptIns)))

FWIW, there is no need to test for the availability of these properties, as an MText object will always have such properties.

Also:
Code: [Select]
(if (= (vlax-property-available-p myMText 'AttachmentPoint) T)
Can be simply:
Code: [Select]
(if (vlax-property-available-p myMText 'AttachmentPoint)