Ok... sitting around the hotel room just really got to me... so I ran out earlier and got a bite to eat and purchased the "Dark Fury" DVD while I was waiting for my food. While I finished waiting I sat down and wrote up the VBA code sample. Below is the sample code that I came up with that selects an object on screen at a specific point and returns the number of objects selected.
Public Sub GetSelection()
Dim acSSet As AcadSelectionSet
Dim dPt(0 To 2) As Double
dPt(0) = 1: dPt(1) = 1: dPt(2) = 0
Set acSSet = ThisDrawing.SelectionSets.Add("SSET")
acSSet.SelectAtPoint dPt
ThisDrawing.Utility.Prompt vbLf + "Number of Objects Selected: " + CStr(acSSet.Count) + vbCrLf + "Command: "
acSSet.Delete
Set acSSet = Nothing
End Sub
These are very simple examples, but show that each language takes some different levels of effort over the other. This doesn't mean that one that one is better for one specific job, it just means that you should use what works best for you. I hope to in the future provide some additional examples, as some get really crazy like creating an object such as a Line... or is it an AcDbLine?
Sincerely,
Lee
Lee,
I am looking for either a VBA or AutoLISP routine that will look at a piece of text, and based on the value of that text, change the visibility state of a dynamic block. I don't want the CAD operator to have to actually "select" anything, but I also would like to be able to apply the process to several other blocks within the drawing. So that as the referenced text changes (to display the correct visibility state) the corresponding block would change as well. I have been working on this for about 6 months, but I have little to NO VBA or LISP experience and trying to teach myself this has been....exhausting....to say the least! I would appreciate ANY help, advice, or voodoo magic you could throw my way. Thank you.
Jessye
Posted by: Jessye Ford | Monday, December 11, 2017 at 09:25 AM
Without a specific use case to design the sample code around, quickly created a very generic example that could be refined a number of ways. The sample code looks for text the text value of "123" and if found, it will change the Visibility State of blocks named "Trees - Imperial". I built the example around Single-line and Multiline text, but it could be done for block attribute values as well. Good luck and let me know if you have any specific questions.
;; Looks for text objects with 123 in them, and if it finds the dynmaic block
;; "Trees - Imperial" it changes the visibility state to Shrub (Plan).
(defun c:blockFlip ( / ssAll nCnt nTextPos lBlocks lText oEnt lEd sTextCompare)
(setq ssAll (ssget "X")
nCnt 0
nTextPos nil
lBlockRefs nil
lTextObjs nil
sTextCompare "123"
)
;; Step through all objects in a drawing and look for the text objects and block references
(while (> (sslength ssAll) nCnt)
(setq oEnt (ssname ssAll nCnt)
lEd (entget oEnt)
)
;; Create two lists; one with text objects (single-line and multiline) and one with block references
;; Note: Could have also done multiple (ssget) statements with a filter
(cond
((or (= (cdr (assoc 0 lEd)) "TEXT")(= (cdr (assoc 0 lEd)) "MTEXT"))
(if (= lTextObjs nil)
(setq lTextObjs (append (list oEnt)))
(setq lTextObjs (append lTextObjs (list oEnt)))
)
)
((= (cdr (assoc 0 lEd)) "INSERT")
(if (= lBlockRefs nil)
(setq lBlockRefs (append (list oEnt)))
(setq lBlockRefs (append lBlockRefs (list oEnt)))
)
)
)
(setq nCnt (1+ nCnt))
)
;; Step through all text objects and look for text strings that match the value of sTextCompare
(foreach oEnt lTextObjs
(progn
(setq lEd (entget oEnt))
(if (= (cdr (assoc 0 lEd)) "TEXT")
(setq nTextPos (vl-string-search sTextCompare (strcase (getpropertyvalue oEnt "TextString"))))
(setq nTextPos (vl-string-search sTextCompare (strcase (getpropertyvalue oEnt "Text"))))
)
;; If a match to text string was found, step through the blocks
(if (/= nTextPos nil)
;; If the block is named "Trees - Imperial" one of the sample dynamic block son the tool palette
;; and the block is indeed a dynamic block, change its viibility style
(if (and (= (getpropertyvalue ent "BlockTableRecord/Name") "Trees - Imperial")
(= (getpropertyvalue ent "IsDynamicBlock") 1)
)
(progn
(setq lDynProps (vlax-safearray->list (vlax-variant-value oDynProps)))
(foreach oDynProp lDynProps
(vla-put-Value oDynProp "Shrub (Plan)")
)
)
)
)
)
)
(princ)
)
Posted by: Lee Ambrosius | Monday, December 11, 2017 at 12:34 PM