TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: donnieworld 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))
)
-
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)
-
Keep in mind that if you are writing Lisp code for BricsCAD you do no need to check this.
(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:
(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)
-
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)
)
-
FWIW .. here's an idea for your justification code:
'attachmentpoint
'(("TL" . 1)
("TC" . 2)
("TR" . 3)
("ML" . 4)
("MC" . 5)
("MR" . 6)
("BL" . 7)
("BC" . 8)
("BR" . 9)
)
)
)
)
-
Also:
(vl-position just '
("""TL""TC""TR""ML""MC""MR""BL""BC""BR")) )
-
Cool :) .. did not know you could feed it strings too.
-
Cool :) .. did not know you could feed it strings too.
Still using integers :wink:
-
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.
-
:-)
-
(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:
(if (= (vlax-property-available-p myMText 'AttachmentPoint) T)
Can be simply:
(if (vlax-property-available-p myMText 'AttachmentPoint)