Recent Posts

Pages: 1 [2] 3 4 ... 10
11
AutoLISP (Vanilla / Visual) / Width of block multiline attribute
« Last post by Spainenins on April 17, 2024, 11:22:44 AM »
Hello!
I have made a lisp routine that does the following:
1)adds a block reference to the model space;
2)changes the value (text string) of an attribute;
3)gets the real width (through bounding box) of the attribute;
4)changes a dynamic block property so that the width of the block reference fits the new text.

It works beautifully, when the attribute is a single-line one. But sadly my colleagues requested I make it a multi-line attribute, so they could use subscripts and superscripts in it.
The problem seems to be that Bounding box of a multi-line attribute is always as if it had it's default text string.
Maybe there is another way to get the width of a multi-line attribute?
Code below:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:ko-addmyblock ()
  2.   (setq mspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))    ;get modelspace of active document
  3.   (setq blkname "MyBlock")      ;name of my block
  4.   (setq attrname "NR")  ;block attribute name (TagString) that I want to change
  5.   (setq newattrvalue "MyNewValue")      ;the new value I want to give to the attribute
  6.   (setq propname "Width")       ;block property name that is supposed to change depending on width of the attribute
  7.   (setq pt (getpoint "Insertion point for block"))      ;get insertion point for the block
  8.   (setq blkobj (vla-insertblock mspace (vlax-3d-point pt) blkname 1 1 1 0))     ;insert block
  9.  
  10.   ;;get the relevant attribute as vla-object
  11.   (setq attrobj
  12.          (car
  13.            (vl-member-if
  14.              '(lambda (blkattrobj) (= (vlax-get-property blkattrobj "TagString") attrname));lambda
  15.              (vlax-safearray->list
  16.                (vlax-variant-value
  17.                  (vlax-invoke-method blkobj "GetAttributes")))
  18.              );vl-member-if
  19.            );car
  20.         );setq
  21.  
  22.   (vla-put-textstring attrobj newattrvalue)     ;change text of the relevant attribute
  23.   (vla-getboundingbox attrobj 'll 'ur)  ;get bounding box of attribute
  24.   (setq attrwidth (apply '- (mapcar 'car (mapcar 'safearray-value (list ur ll)))))      ;get width of the bounding box
  25.  
  26.   ;;get the relevant property as vla-object
  27.   (setq propobj
  28.          (car
  29.            (vl-member-if
  30.              '(lambda (blkpropobj) (= (vlax-get-property blkpropobj "PropertyName") propname));lambda
  31.              (vlax-invoke blkobj "GetDynamicBlockProperties")
  32.              );vl-member-if
  33.            );car
  34.         );setq
  35.  
  36.   (vla-put-value propobj (+ 2.0 attrwidth))     ;change it's value
  37.   (princ)
  38. );defun

The block is a really simple one with one attribute called "NR", and one custom property called "Width".


EDIT (John): Fixed code tag.
12
Wow! This is an unexpected treat. Thanks ribarm!


QUESTION

What factors / complexities will a fledgling programmer face when using text entities to base other text's alignment?

Yours,

C.
13
Here... It took me some time to cobble this all to one single *.lsp that'll have built in *.dcl... It should work, but alignments are to only straight orthogonal lines, weather they are left, right, top or bottom... This is what is provided and in *.dcl...

HTH.
M.R.
14
XDRX-API / [XDrX-PlugIn(146)] Make Hatch along path
« Last post by xdcad on April 17, 2024, 08:03:37 AM »

Code: [Select]
(defun c:xdtb_hapath (/ ang box clr ha ha1 pat remove scl ss tm x)
  (xd::doc:getdouble (xdrx-string-multilanguage "\n上方距离" "\nDistance above") "#xd-var-global-up-dist"
     10.0
  )
  (xd::doc:getdouble (xdrx-string-multilanguage "\n下方距离" "\nDistance below") "#xd-var-global-down-dist"
     10.0
  )
  (if (setq ha (xd::odcl:hatchdlg1 "" "" 1))
    (progn
      (setq pat (cadr (assoc "Pattern" ha))
    remove (cadr (assoc "RemoveBoundary" ha))
    scl (cadr (assoc "Scale" ha))
    clr (cadr (assoc "Color" ha))
    ang (xdrx_math_degtor (atof (cadr (assoc "Angle" ha))))
    tm (atoi (cadr (assoc "Transparency" ha)))
      )
      (if (setq ss (xdrx-ssget (xdrx-string-multilanguage "\n拾取路径多段线<退出>:"
  "\nPick Path Polyline<Exit>:"
       ) '((0 . "*polyline") (-4 . "&=")
(70 . 0)
       )
   )
  )
(progn
  (xdrx-begin)
  (xdrx-sysvar-push '("BoxFillet" 1))
  (mapcar
    '(lambda (x)
       (setq box (xdrx-getpropertyvalue x "tobox" #xd-var-global-down-dist #xd-var-global-up-dist 0.0
0.0
)
       )
       (setq ha1 (xdrx-hatch-make (xdrx-polyline-make box t)))
       (xdrx-setpropertyvalue ha1 "PatternName" pat "PatternScale" scl "PatternAngle" ang "color" clr
      "Transparency" tm
       )
       (if (= 1 remove)
(progn
   (xdrx-entity-delete (xdrx-getpropertyvalue ha1 "assocobjids"))
)
       )
     )
    (xdrx-ss->ents ss)
  )
  (xdrx-sysvar-pop)
  (xdrx-end)
)
      )
    )
  )
  (princ)
)
15
AutoLISP (Vanilla / Visual) / Re: Ssget filter for mirrored multileader
« Last post by ribarm on April 17, 2024, 07:37:29 AM »
Yes, I found it. Thank you!
I did have to add the first 11 to the <or set as well:
Code - Auto/Visual Lisp: [Select]
  1.   '(
  2.     (0 . "MULTILEADER")
  3.     (-4 . "<or")
  4.       (11 -1.0  0.0  0.0)
  5.       (11  0.0 -1.0  0.0)
  6.       (11  0.0  0.0 -1.0)
  7.     (-4 . "or>")
  8.   )
  9. )

I think you are making mistake with this... There should be one 11 with positive 1.0... Look careful in my example...
16
Hi BIGAL,

I have attached the requested LSP file (and reattached the DCL as well).

I appreciate your interest and look forward to what is now a puzzle to me!

P.S.: In the file attach field, I just noticed the link "more attachments" below it. :idea:

Thanks,

Clint
17
AutoLISP (Vanilla / Visual) / Modify Lee Lisp BFind to run on opened drawings only
« Last post by HasanCAD on April 17, 2024, 07:07:45 AM »
I am using LEE lisp BFind (thanks LEE)
How to modify the lisp to this setting and use as default.
- Only to run on opened drawings only.
- Clear saved list.

Thanks
18
AutoLISP (Vanilla / Visual) / Re: Ssget filter for mirrored multileader
« Last post by dexus on April 17, 2024, 04:38:13 AM »
Yes, I found it. Thank you!
I did have to add the first 11 to the <or set as well:
Code - Auto/Visual Lisp: [Select]
  1.   '(
  2.     (0 . "MULTILEADER")
  3.     (-4 . "<or")
  4.       (11 -1.0  0.0  0.0)
  5.       (11  0.0 -1.0  0.0)
  6.       (11  0.0  0.0 -1.0)
  7.     (-4 . "or>")
  8.   )
  9. )
19
AutoLISP (Vanilla / Visual) / Re: Ssget filter for mirrored multileader
« Last post by ribarm on April 17, 2024, 04:23:50 AM »
Try this :

Code - Auto/Visual Lisp: [Select]
  1. (setq ss (ssget (list (cons 0 "MULTILEADER") (list 11 0.0 0.0 -1.0) (cons -4 "<or") (list 11 -1.0 0.0 0.0) (list 11 1.0 0.0 0.0) (cons -4 "or>"))))
  2.  
20
AutoLISP (Vanilla / Visual) / Ssget filter for mirrored multileader
« Last post by dexus on April 17, 2024, 04:13:22 AM »
Hi all,

I'm trying to select only mirrored multileaders, but I cant seem to get the ssget filter correct.

The normal of a multileader is set in the first appearance of dxf code 11 and if it is mirrored, it is set to (0.0 0.0 -1.0)

But other things like where the leaders are connected are also saved in dxf code 11.

If I try to match it directly it doesn't match anything because not all the 11's are the same:
Code - Auto/Visual Lisp: [Select]
  1. (ssget '((0 . "MULTILEADER") (11 0.0 0.0 -1.0)))

If I try to find all the non default normals it matches non-mirrored multileaders as well, because it matches the second 11 as non default:
Code - Auto/Visual Lisp: [Select]
  1. (ssget '((-4 . "<and") (0 . "MULTILEADER") (-4 . "!=") (11 0.0 0.0 1.0) (-4 . "and>")))

Is it possible to set an ssget filter for only the first appearance of 11?
Or is there another way to do this?
Pages: 1 [2] 3 4 ... 10