Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Delete Point Groups

19 REPLIES 19
SOLVED
Reply
Message 1 of 20
jroot
1842 Views, 19 Replies

Delete Point Groups

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!

19 REPLIES 19
Message 2 of 20
Jeff_M
in reply to: jroot

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)
)

 

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 20
jroot
in reply to: Jeff_M

Awesome!  Worked perfect - thanks Jeff!

Message 4 of 20
htls69
in reply to: Jeff_M

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.

Allen Robberson
Credit where credit is due! Give kudos or accept as solution whenever you can.
Message 5 of 20
hippe013
in reply to: htls69

(vlax-for grp groups
  (if (not (wcmatch (vlax-get grp 'name) "*2017*,*2018*"))
    (if (wcmatch (vlax-get grp 'name) "*.#,*.##")
      (setq groupstoremove (cons grp groupstoremove))
      )
    )
  )
Message 6 of 20
htls69
in reply to: hippe013

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)
)
Allen Robberson
Credit where credit is due! Give kudos or accept as solution whenever you can.
Message 7 of 20
tyronebk
in reply to: htls69

There is a missing closing parenthesis. Place the missing one just above the final (princ):

        (vlax-release-object C3D)
      )
    )
  )
  (princ)
)
Message 8 of 20
htls69
in reply to: tyronebk

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)
)
Allen Robberson
Credit where credit is due! Give kudos or accept as solution whenever you can.
Message 9 of 20
Jeff_M
in reply to: tyronebk

@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
Jeff_M, also a frequent Swamper
EESignature
Message 10 of 20
htls69
in reply to: Jeff_M

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

Allen Robberson
Credit where credit is due! Give kudos or accept as solution whenever you can.
Message 11 of 20
tyronebk
in reply to: Jeff_M

@Jeff_M  Thanks for the correction. I got it to close but didn't actually test it. *tsk* *tsk*

Message 12 of 20
htls69
in reply to: htls69

(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)
)
Allen Robberson
Credit where credit is due! Give kudos or accept as solution whenever you can.
Message 13 of 20
Kélcyo
in reply to: Jeff_M

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();
                    }
                }
            }      
        }
Message 14 of 20
hippe013
in reply to: Kélcyo

(_pgId != ObjectId.Null)
Message 15 of 20
Jeff_M
in reply to: Kélcyo

In addition to what @hippe013 mentioned, I believe you will get an error if you try to delete the "_All Points" group so you should check the name of the group before deleting it.

Jeff_M, also a frequent Swamper
EESignature
Message 16 of 20
Kélcyo
in reply to: Jeff_M

I want to delete only the groups regardless of the name, but preserve the same points in the document, these without assignment in groups.

Message 17 of 20
hippe013
in reply to: Jeff_M

@Jeff_M The "_All Points" point group will have an ObjectId that is ObjectId.Null. 

Message 18 of 20
hippe013
in reply to: Kélcyo

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. 

Message 19 of 20
Jeff_M
in reply to: Kélcyo

@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);
            }
        }

  

Jeff_M, also a frequent Swamper
EESignature
Message 20 of 20
Kélcyo
in reply to: Jeff_M

Very good. Solved in a few lines ...
Thanks

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report