@Bratz2 ,
This should be a good foundation. I'm not sure why you were trying to retrieve block names from Raw descriptions. That would make it extremely difficult since sometimes Raw Descriptions can have multiple descriptions, linework codes, and comments.
So if you're making a legend, then let's retrieve what blocks are actually being used by cogo points. Then we don't have to identify every Raw Description possible.
Here is a Lisp that automatically searches all points in drawing, retrieves their blocks, then asks you to pick a point (the top of the legend), then it creates the blocks straight downward. It has options for custom scaling, layering, and custom text (so you can add your Legend text). Hope it helps
((lambda ( / C3D)
(setq C3D (strcat "HKEY_LOCAL_MACHINE\\"
(if vlax-user-product-key
(vlax-user-product-key)
(vlax-product-key)
);if
);strcat
C3D (vl-registry-read C3D "Release")
C3D (substr
C3D
1
(vl-string-search "." C3D (+ (vl-string-search "." C3D) 1))
);substr
*C3D* (vla-getinterfaceobject
(vlax-get-acad-object)
(strcat "AeccXUiLand.AeccApplication." C3D)
);vla-getinterfaceobject
*C3DDoc* (vla-get-activedocument *C3D*)
);setq
));lambda/eval
(defun c:LEGEND ( / cLayer num style blkName scale layer customText blkList doc cSpace pt pt3D blk ptMin ptMax fullSize halfSize ptMid sizeList spacingBetweenBlocks)
(setq cLayer (getvar 'CLAYER))
;; Retrieve block names used by CoGo points and appropriate scales (if necessary)
(vlax-for point (vlax-get *C3DDoc* 'Points)
(setq num (itoa (vlax-get point 'Number)))
(setq style (vlax-get point 'Style))
(if (and style (= 2 (vlax-get style 'MarkerType)))
(progn
(setq blkName (vlax-get style 'MarkerSymbolName))
;; If unique scale factors, layering, or text are required based on block name, do so here..
(cond
;((eq (strcase blkName) (strcase "Unique_Block_Name")) (setq scale 0.75 layer "MY-LAYER-NAME" customText "This is a Unique Block"))
(t (setq scale 1.0 layer cLayer customText "-----"))
);cond
(if (not (assoc blkName blkList))
(setq blkList (cons (list blkName scale layer customText) blkList))
);if
);progn
;else
(if style (prompt (strcat "\nPoint # " num " does not use a Block as symbol..")))
);if
);vlax-for
;; Sort blocks by name, optional
(setq blkList (vl-sort blkList '(lambda (b1 b2) (< (car b1) (car b2)))))
;; Get space info for inserting blocks
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq cSpace (if (= (getvar 'cvport) 1) (vla-get-PaperSpace doc) (vla-get-ModelSpace doc)))
;; user determines location of block insertions
(initget 1) (setq pt (getpoint "\nSelect Insertion Point: "))
(setq pt3D (vlax-3d-point pt))
(setq spacingBetweenBlocks 0.1) ;;<--- Set this spacing variable as necessary
;; insert blocks (align as necessary)
(foreach blkData blkList
(setq blkName (car blkData) scale (cadr blkData) layer (caddr blkData) customText (cadddr blkData))
(setq blk
(vla-insertblock
cSpace
pt3D
blkName
scale ;<-- x Scale
scale ;<-- y Scale
scale ;<-- z Scale
0 ;<-- Rotation
);vla-insertblock
);setq
(vlax-put-property blk 'Layer layer)
;; since we're stacking blocks, determine area, and prep for moving blocks
(vla-GetBoundingBox blk 'ptMin 'ptMax)
(setq ptMin (vlax-safearray->list ptMin) ptMax (vlax-safearray->list ptMax))
(setq fullSize (- (cadr ptMax) (cadr ptMin)))
(setq halfSize (* 0.5 fullSize))
(if sizeList
(progn
;; Use ptMid to place text next to blocks
(setq ptMid (vlax-3d-point (polar pt (* 1.5 pi) (+ (apply '+ sizeList) halfSize))))
(vla-move
blk
(vlax-3d-point ptMax)
(vlax-3d-point (list (car ptMax) (cadr (polar pt (* 1.5 pi) (apply '+ sizeList)))))
);vla-move
(setq sizeList (cons (+ fullSize spacingBetweenBlocks) sizeList))
);progn
;else
(setq sizeList (cons (+ halfSize spacingBetweenBlocks) sizeList))
);if
);foreach
(prompt "\nLEGEND Complete.")
(princ)
);defun
Best,
~DD