Jump to content

Recommended Posts

Posted

Hi all,

Ive spent all weekend with my head in Afralisp, Google and various other sources, Im a Lisp newbie and this will be my first intermediate (dare I call it) routine, though credit should be given to people who have already contributed to my various sources of reference!

 

The routine:

Copies an Mleader > Explodes the copy > Removes the leader components > Places the text on a unique layer based on the original layer but with a suffix.

 

What Im struggling with is that the mtext does not inherit the annotive scales of the original mleader (only the current scale) and I cant figure out how to make selection set of said scales so I can add them back to the copied mtext.

 

The code so far, be gentle :D :

 

;============================================================
;MLeader Halo____G Beaumont 01/04/13
;============================================================
(defun c:ML2HALO ( / msel1 sfx msel2 oldlayer ent entdata lay1 lay_name)
(Princ "\nSelect Mleader or Dimension to HALO (CAN NOT be a true type font)...")
 (setq msel1 (ssget))
  (setq sfx "_HALO")
 (command "copy" msel1 "" "0,0" "0,0")
  (setq msel2 (ssget "p"))
  (setvar "qaflags" 1)
   (command "_.explode" msel2 "")
    (setvar "qaflags" 0)
  (setq msel2 (ssget "p"))
 (ssget "p" '((-4 . "<not") (0 . "Mtext") (-4 . "not>")))
  (command "erase" "p" "")
;============================================================
;Layer control
;============================================================
(setq oldlayer (getvar "CLAYER"))
 (entlast)
  (setq ent (entlast))
   (setq entdata (entget ent))
    (assoc 8 entdata)
     (cdr (assoc 8 entdata))    
      (setq lay1 (cdr (assoc 8 entdata)))
       (setq lay_name (strcat lay1 sfx))
(command "-LAYER" "M" lay_name "LW" "2" "" "C" "255" "" "")
 (command "_chprop" msel2 "" "LA" lay_name "C" "bylayer" "Annotative" "yes" "")
  (setvar "CLAYER" oldlayer)
(princ)
)
;============================================================
;End
;============================================================

Posted

What you need to do is "grab" the current Annoscale(s) of the mleader object and apply it to ent . but that will assume all selected Mleader have the same Annoscales. [easy part]

 

(Defun GetAnnoscale (ed / scLst)
;;;	  Irné 	;;;
(if (and
             ;; Get the XDictionary attached to the object
             (setq xn (vl-position '(102 . "{ACAD_XDICTIONARY") ed))
             (setq xn (cdr (nth (1+ xn) ed)))
             (setq xd (entget xn))
             ;; Get the Context Data Management dictionary attached to the XDictionary
             (setq cdn (vl-position '(3 . "AcDbContextDataManager") xd))
             (setq cdn (cdr (nth (1+ cdn) xd)))
             (setq cdd (entget cdn))
             ;; Get the Annotation Scales dictionary attached to the CD
             (setq asn (vl-position '(3 . "ACDB_ANNOTATIONSCALES") cdd))
             (setq asn (cdr (nth (1+ asn) cdd)))
             (setq asd (entget asn))
             ;; Get the 1st scale attached
             (setq cn (assoc 3 asd))
             (setq cn (member cn asd))
           )
         ;; Step through all scales attached
         (while cn
           (if (and (= (caar cn) 350) ;It it's pointing to a scale record
                    ;; Get the record's data
                    (setq cd (entget (cdar cn)))
                    ;; Get the Context data class
                    (setq sn (assoc 340 cd))
                    (setq sd (entget (cdr sn)))
                    (setq sn (assoc 300 sd))
                    ;; Check if the scale is already in the list
                    (not (vl-position (cdr sn) scLst))
               )
             (setq scLst (cons (cdr sn) scLst))
           )
           (setq cn (cdr cn))
         )
       ) scLst
)

 

Otherwise you would need to iterate thru the selected Mleader entities and yes explode the items one by one.

 

Holler if you need help :)

Posted

Thanks a lot pBe,

I shall find a quiet corner, cross my legs and rock slowly as I try to digest the new 20 or so commands I dont understand, including the VL stuff I havent even started trying to learn yet :)

Posted

:lol:The only VL thing in pBe's code is vl-position. That's a rather simple method to figure out, it's the converse of the nth function. Say you have a list of integers and want to find the position of a specific integer in that list:

(setq sampleList '(6 2 4 5 1 )
(vl-position 4  sampleList) ;Returns 2 as the 0-based index position
(nth 2 sampleList) ;Returns 4 as the item at position 2

 

As for that code, I'm a bit ashamed of all the extra stuff I did in it which was quite unnecessary. There are some other ways of getting around to the same thing. Most notable would be the dict* functions, which are the "official" ways to work with dictionaries. For some newer version of my functions look in this lisp: http://sourceforge.net/p/caddons/code/67/tree/General/Scales.LSP

 

Basically what's going on is that anno scales are listed in the dictionaries attached to the drawing (i.e. attached to the "ACAD_SCALELIST" dictionary attached to the namedobjdict entity) as XRecord-like entities. Then each entity with scales applied to it has a dictionary attached to its XDictionary, depending on what type of entity this might be "ACDB_ANNOTATIONSCALES" or "ASDK_XREC_ANNOTATION_SCALE_INFO". Then that contains one or more links to the main scales in the ACAD_SCALELIST. It sounds a bit convoluted, but that's "usual" when working with dictionaries. :roll:

Posted

As for that code, I'm a bit ashamed of all the extra stuff I did in it which was quite unnecessary

 

:lol: my bad Irné , i just pasted the first routine i saw that deals with Annocscales. I'm in a bit of lazy mode these days to write codes.

 

Cheers

 

I'll have a look-see at your new version later. :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...