View Full Version : Searching groupnames and filtering the results
joel.shelstrom
2007-06-06, 05:10 PM
Hello Everyone,
I was given a program to search the group names in my drawings and to export to a txt file. I am trying to modify this program to exclude the AT_ANNOT group name from the list, which i can not get to work. I have pasted my code below.
(defun c:getgroups ( / groupnames)
(vl-load-com)
; Cycles through all entities in a drawing and gets groups
(vlax-for grp (vla-get-groups
(vla-get-activedocument
(vlax-get-acad-object)
)
)
)
(if (vl-string-search "AT_" (Vla-get-name grp)) ; grabs all groups that have AT_ at the start of the name
(setq groupnames
((while (not (Vla-get-name grp) (vl-string-search "AT_ANNOT"))
(cons (vla-get-name grp) groupnames))) ; creates a list of each group name
)
)
groupnames ; returns this variable to function name
)
;function to Append groupnames to a CSV file
(defun c:XdataTOCSV (/ strText strText2)
(setq strFilename "c:/temp/XDATA.csv")
(setq lstOfSublists (c:getgroups)) ; assigns the results of GETGROUPS function to variable
(setq strChar ",")
(setq z (open strFileName "a")) ;opens filename for appending
(foreach lstSubList lstOfSublists
(setq strText (strcat lstSubList "," (getvar 'dwgname))) ;concatanates groupname , and dwgname and assigns to variable
(if strText (write-line strText z)) ; writes to CSV file if strText has data
)
(close z) ; closes csv file
(princ)
)The part i modified , that i can not get to work
(setq groupnames
((while (not (Vla-get-name grp) (vl-string-search "AT_ANNOT"))
(cons (vla-get-name grp) groupnames))) ; creates a list of each group name
)Thanks,
[ Moderator Action = ON ] What are [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code) [ Moderator Action = OFF ]
tyshofner
2007-06-06, 05:58 PM
Try this:
(defun c:getgroups ( / groupnames)
(vl-load-com)
; Cycles through all entities in a drawing and gets groups
(vlax-for grp (vla-get-groups (vla-get-activedocument (vlax-get-acad-object)))
(if (vl-string-search "AT_" (Vla-get-name grp)) ; grabs all groups that have AT_ at the start of the name
(if (/= (vla-get-name grp) "AT_ANNOT")
(setq groupnames (cons (vla-get-name grp) groupnames)) ; creates a list of each group name
)
)
)
groupnames ; returns this variable to function name
)
;function to Append groupnames to a CSV file
(defun c:XdataTOCSV (/ strText strText2)
(setq strFilename "c:/temp/XDATA.csv")
(setq lstOfSublists (c:getgroups)) ; assigns the results of GETGROUPS function to variable
(setq strChar ",")
(setq z (open strFileName "a")) ;opens filename for appending
(foreach lstSubList lstOfSublists
(setq strText (strcat lstSubList "," (getvar 'dwgname))) ;concatanates groupname , and dwgname and assigns to variable
(if strText (write-line strText z)) ; writes to CSV file if strText has data
)
(close z) ; closes csv file
(princ)
)
You could combine the two IF statements into one by using the "and" function:
(if (and (vl-string-search "AT_" (Vla-get-name grp)) (/= (vla-get-name grp) "AT_ANNOT")) ; grabs all groups that have AT_ at the start of the name
(setq groupnames (cons (vla-get-name grp) groupnames)) ; creates a list of each group name
)
Ty :mrgreen:
joel.shelstrom
2007-06-06, 07:26 PM
tyshofner,
Thanks for the reply. I tried that and it did work if i entered in the exact string on one of the groups that needs to be filtered out (E.G. AT_ANNOT_EJMZO6W6_46Y). I tried to use a wild card (AT_ANNOT_*), but that doesn't work either. Do you have any other suggestions to what might work?
Thanks,
Joel
ccowgill
2007-06-07, 11:20 AM
tyshofner,
Thanks for the reply. I tried that and it did work if i entered in the exact string on one of the groups that needs to be filtered out (E.G. AT_ANNOT_EJMZO6W6_46Y). I tried to use a wild card (AT_ANNOT_*), but that doesn't work either. Do you have any other suggestions to what might work?
Thanks,
Joel
(if (wcmatch (vla-get-name grp) "AT_ANNOT*")
(setq groupnames (cons (vla-get-name grp) groupnames)) ; creates a list of each group name
)
have you tried this?
tyshofner
2007-06-07, 02:02 PM
tyshofner,
Thanks for the reply. I tried that and it did work if i entered in the exact string on one of the groups that needs to be filtered out (E.G. AT_ANNOT_EJMZO6W6_46Y). I tried to use a wild card (AT_ANNOT_*), but that doesn't work either. Do you have any other suggestions to what might work?
Thanks,
Joel
Sorry Joel, thought the group name you were wanting to exclude was simply "AT_ANNOT". As mentioned above the "wcmatch" function should achieve your desired result.
Ty :mrgreen:
joel.shelstrom
2007-06-07, 07:45 PM
tyshofner,
Thanks for the reply. So i modified my program to include the following;
(if (wcmatch (vla-get-name grp) "AT_ANNOT*")
(setq groupnames (cons (vla-get-name grp) groupnames)) ; creates a list of each group name
)
I still can't get it to exclude AT_ANNOT* from my list. I have tried to everything i could think of with the wcmatch command, but it never works.
Here is how i thought it would work, but of course it doesn't.
(if (vl-string-search "AT_" (Vla-get-name grp))
(if (/= (vl-string-search "AT_" (Vla-get-name grp))(wcmatch (vla-get-name grp) "AT_ANNOT*"))
(setq groupnames (cons (vla-get-name grp) groupnames)) ; creates a list of each group name
)
(setq groupnames (cons (vla-get-name grp) groupnames)) ; creates a list of each group name
)
)
Not sure what i am doing wrong,
I appreciate all your help.
Joel
tyshofner
2007-06-07, 08:42 PM
Hi Joel,
"wcmatch" returns T or nil so you have to test for that. If it is nil then add the group.
Try this out:
(defun c:getgroups ( / groupnames)
(vl-load-com)
; Cycles through all entities in a drawing and gets groups
(vlax-for grp (vla-get-groups (vla-get-activedocument (vlax-get-acad-object)))
(if (vl-string-search "AT_" (Vla-get-name grp)) ; grabs all groups that have AT_ at the start of the name
(if (= (wcmatch (vla-get-name grp) "AT_ANNOT*") nil)
(setq groupnames (cons (vla-get-name grp) groupnames)) ; creates a list of each group name
)
)
)
groupnames ; returns this variable to function name
)
;function to Append groupnames to a CSV file
(defun c:XdataTOCSV (/ strText strText2)
(setq strFilename "c:/temp/XDATA.csv")
(setq lstOfSublists (c:getgroups)) ; assigns the results of GETGROUPS function to variable
(setq strChar ",")
(setq z (open strFileName "a")) ;opens filename for appending
(foreach lstSubList lstOfSublists
(setq strText (strcat lstSubList "," (getvar 'dwgname))) ;concatanates groupname , and dwgname and assigns to variable
(if strText (write-line strText z)) ; writes to CSV file if strText has data
)
(close z) ; closes csv file
(princ)
)
Ty :mrgreen:
joel.shelstrom
2007-06-07, 08:47 PM
thank you, that worked perfectly.
Powered by vBulletin® Version 4.1.11 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.