Does anyone have a LISP that could mass delete all those pesky duplicate point groups that sometimes find their way into DWGs?
They duplicate the point group name and tack on a .1 or .2 or .3 at the end.
The LISP would find all point groups that end in .# and delete it.
Thanks!
Solved! Go to Solution.
Solved by Jeff_M. Go to Solution.
This should do it:
(defun c:deletePGdups (/ C3D C3DDOC GROUPS GROUPSTOREMOVE) (vl-load-com) (if (and (setq *acad* (vlax-get-acad-object)) (setq C3D (strcat "HKEY_LOCAL_MACHINE\\" (if vlax-user-product-key (vlax-user-product-key) (vlax-product-key) ) ) C3D (vl-registry-read C3D "Release") C3D (substr C3D 1 (vl-string-search "." C3D (+ (vl-string-search "." C3D) 1) ) ) C3D (vla-getinterfaceobject (vlax-get-acad-object) (strcat "AeccXUiLand.AeccApplication." C3D) ) ) (setq C3Ddoc (vla-get-activedocument C3D)) ) (progn (setq groups (vlax-get c3ddoc 'pointgroups)) (vlax-for grp groups (if (wcmatch (vlax-get grp 'name) "*.#,*.##") (setq groupstoremove (cons grp groupstoremove)) ) ) (if groupstoremove (foreach grp groupstoremove (vlax-invoke groups 'remove grp) ) ) (vlax-release-object C3D) ) ) (princ) )
I was wondering if this could be modified to not delete point groups with 2017 or 2018 in the name of the group?
We insert points based in groups based on date of field work and it is deleting the point groups.
(vlax-for grp groups (if (not (wcmatch (vlax-get grp 'name) "*2017*,*2018*")) (if (wcmatch (vlax-get grp 'name) "*.#,*.##") (setq groupstoremove (cons grp groupstoremove)) ) ) )
I am getting this error when trying to load this
(LOAD "C:/Users/arobberson/Desktop/DPG.lsp") ; error: malformed list on input
any help would be awesome
(defun c:DPG (/ C3D C3DDOC GROUPS GROUPSTOREMOVE) (vl-load-com) (if (and (setq *acad* (vlax-get-acad-object)) (setq C3D (strcat "HKEY_LOCAL_MACHINE\\" (if vlax-user-product-key (vlax-user-product-key) (vlax-product-key) ) ) C3D (vl-registry-read C3D "Release") C3D (substr C3D 1 (vl-string-search "." C3D (+ (vl-string-search "." C3D) 1) ) ) C3D (vla-getinterfaceobject (vlax-get-acad-object) (strcat "AeccXUiLand.AeccApplication." C3D) ) ) (setq C3Ddoc (vla-get-activedocument C3D)) ) (progn (setq groups (vlax-get c3ddoc 'pointgroups)) (vlax-for grp groups (if (not (wcmatch (vlax-get grp 'name) "*2017*,*2018*")) (if (wcmatch (vlax-get grp 'name) "*.#,*.##") (setq groupstoremove (cons grp groupstoremove)) ) ) (if groupstoremove (foreach grp groupstoremove (vlax-invoke groups 'remove grp) ) ) (vlax-release-object C3D) ) ) (princ) )
There is a missing closing parenthesis. Place the missing one just above the final (princ):
(vlax-release-object C3D) ) ) ) (princ) )
using civil 3d 2017
get this error
; error: null interface pointer: #<VLA-OBJECT 0000000000000000>
(defun c:DPG (/ C3D C3DDOC GROUPS GROUPSTOREMOVE) (vl-load-com) (if (and (setq *acad* (vlax-get-acad-object)) (setq C3D (strcat "HKEY_LOCAL_MACHINE\\" (if vlax-user-product-key (vlax-user-product-key) (vlax-product-key) ) ) C3D (vl-registry-read C3D "Release") C3D (substr C3D 1 (vl-string-search "." C3D (+ (vl-string-search "." C3D) 1) ) ) C3D (vla-getinterfaceobject (vlax-get-acad-object) (strcat "AeccXUiLand.AeccApplication." C3D) ) ) (setq C3Ddoc (vla-get-activedocument C3D)) ) (progn (setq groups (vlax-get c3ddoc 'pointgroups)) (vlax-for grp groups (if (not (wcmatch (vlax-get grp 'name) "*2017*,*2018*")) (if (wcmatch (vlax-get grp 'name) "*.#,*.##") (setq groupstoremove (cons grp groupstoremove)) ) ) (if groupstoremove (foreach grp groupstoremove (vlax-invoke groups 'remove grp) ) ) (vlax-release-object C3D) ) ) ) (princ) )
@tyronebk, the missing parenthesis is actually the one needed to end the (vlax-for grp ... loop
(vlax-for grp groups (if (not (wcmatch (vlax-get grp 'name) "*2017*,*2018*")) (if (wcmatch (vlax-get grp 'name) "*.#,*.##") (setq groupstoremove (cons grp groupstoremove)) ) )
);;this was the missing one (if groupstoremove
Can you send me the complete lisp
I am trying to edit it to make it work but i get error eveytime i try to load it
Thanks
(defun c:DPG (/ C3D C3DDOC GROUPS GROUPSTOREMOVE) (vl-load-com) (if (and (setq *acad* (vlax-get-acad-object)) (setq C3D (strcat "HKEY_LOCAL_MACHINE\\" (if vlax-user-product-key (vlax-user-product-key) (vlax-product-key) ) ) C3D (vl-registry-read C3D "Release") C3D (substr C3D 1 (vl-string-search "." C3D (+ (vl-string-search "." C3D) 1) ) ) C3D (vla-getinterfaceobject (vlax-get-acad-object) (strcat "AeccXUiLand.AeccApplication." C3D) ) ) (setq C3Ddoc (vla-get-activedocument C3D)) ) (progn (setq groups (vlax-get c3ddoc 'pointgroups)) (vlax-for grp groups (if (not (wcmatch (vlax-get grp 'name) "*2017*,*2018*")) (if (wcmatch (vlax-get grp 'name) "*.#,*.##") (setq groupstoremove (cons grp groupstoremove)) ) ) ) (if groupstoremove (foreach grp groupstoremove (vlax-invoke groups 'remove grp) ) ) (vlax-release-object C3D) ) ) (princ) )
this returns an error "eNullObjectID" and i can't interact to delete all groups of points...
private void RemoveAllPointGroup()
{
PointGroupCollection _pgCol = _civildoc.PointGroups;
foreach (var _pgId in _pgCol)
{
if (_pgId != null)
{
PointGroup _pg = _pgId.GetObject(OpenMode.ForWrite) as PointGroup;//eNullObjectId
if (_pg != null)
{
_pg.Erase();
}
}
}
}
I want to delete only the groups regardless of the name, but preserve the same points in the document, these without assignment in groups.
In deleteing points groups you will have to check the following:
1) that the id is not ObjectId.Null (In my testing sometimes, but not always, the "_All Points" id is ObjectId.Null).
2) that the Point Group is not the "_All Points" point group (as @Jeff_M mentioned this will cause an error)
3) use the remove method from the PointGroupCollection and not the pointgroup method erase.
4) Build a collection of ids to remove and remove after. If you remove a point group in a foreach of the pointgroupCollection you will be modifying the collection in a loop. This will cause an error.
@Kélcyo This should do it:
public void pgclear()
{
var groups = CivilApplication.ActiveDocument.PointGroups;
var groupIds = groups.ToList<AcDb.ObjectId>();
var apId = groups.AllPointsPointGroupId;
foreach(AcDb.ObjectId id in groupIds )
{
if (id != apId)
groups.Remove(id);
}
}
Can't find what you're looking for? Ask the community or share your knowledge.