Author Topic: exclude entnext polyline subentities?  (Read 3728 times)

0 Members and 1 Guest are viewing this topic.

danallen

  • Guest
exclude entnext polyline subentities?
« on: November 08, 2010, 02:42:51 AM »
I have the following code which duplicates entities in place, then sets Previous to the new entities so that I can move or change their layer. It has a bug that the "previous" entities returned includes one of the original entities, IF the last is a polyline. I believe this is because ENTNEXT cycles through and returns subentities.

Question - how can I exclude that from happening in the XYZ_AFTER function?

Thanks,

Dan

Code: [Select]
;;; Duplicates objects
(defun-q c:CD ( / count ss1 ss2 elst)
  (princ "Copy-DUPLICATE\n")
  (if (setq ss1   (ssget ":L")) ;if stuff selected
    (progn
      (setq elst (entlast) ;remember last entity
            count (sslength ss1)
            ss2   (ssadd)
      )
      (while (> count 0) ;reverse selection set
        (ssadd (ssname ss1 (setq count (1- count))) ss2)
      ) ;end while
      (command ".copy" ss2 "" "@" "@") ;copy in same place
      (command ".select" (XYZ_AFTER elst) "") ;reset previous to new entities since last
    ) ;end progn
  ) ;end if
  (princ)
)
;==============================================================================
; Returns selection set of all entities after passed in entity name
; from CAD Cookbook utilities
;==============================================================================
(defun-q XYZ_AFTER (ename / ss)
  (setq ss (ssadd)) ;create selection set
  (if ename
    (while (setq ename (entnext ename))
       (ssadd ename ss) ;add entities to set
    )
  ) ;end if
  (if (> (sslength ss) 0) ss) ;return nil if no entities
)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: exclude entnext polyline subentities?
« Reply #1 on: November 08, 2010, 03:07:22 AM »
Classic problem, classic solution:
Code: [Select]
(defun kg:GetLast ( / ent newEnt)
  (setq ent (entlast))
  (while (setq newEnt (entnext ent))
    (setq ent newEnt)
  )
  ent
)

Change this line in your code:
Code: [Select]
     (setq elst (entlast) ;remember last entityTo:
Code: [Select]
     (setq elst (kg:GetLast) ;remember last entity

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: exclude entnext polyline subentities?
« Reply #2 on: November 08, 2010, 07:20:36 AM »
Not sure if I'm way off the mark with something like this?

Code: [Select]
(defun c:cd ( / s ss )
  (vl-load-com) (setq s (ssadd))

  (if (ssget "_:L")
    (progn
      (vlax-for obj
        (setq ss
          (vla-get-ActiveSelectionSet
            (vla-get-ActiveDocument (vlax-get-acad-object))
          )
        )
        (ssadd (vlax-vla-object->ename (vlax-invoke obj 'copy)) s)
      )
      (vla-delete ss) (sssetfirst nil s)
    )
  )
  (princ)
)

danallen

  • Guest
Re: exclude entnext polyline subentities?
« Reply #3 on: November 08, 2010, 08:07:56 PM »
Roy - thank you.  For others learning (like me), here is what is going on:
Code: [Select]
[color=red](draw a polyline)
[/color]Command: (entlast)
<Entity name: 7ef8cf10>

Command: (kg:getlast)
<Entity name: 7ef8cf38>

Command: list
Select objects: 1 found

Select objects:
                  POLYLINE  Layer: "0"
                            Space: Model space
                   Handle = [color=red]9A[/color]
            Closed
    starting width    0.0000
      ending width    0.0000
              area   15.4793
         perimeter   15.9423

                  VERTEX    Layer: "0"
                            Space: Model space
                   Handle = 9B
                at point, X=  18.0988  Y=  14.1223  Z=   0.0000
    starting width    0.0000
      ending width    0.0000

                  VERTEX    Layer: "0"
                            Space: Model space
                   Handle = 9C
                at point, X=  18.0988  Y=  17.4711  Z=   0.0000
    starting width    0.0000
      ending width    0.0000

                  VERTEX    Layer: "0"
                            Space: Model space
                   Handle = 9D
                at point, X=  22.7211  Y=  17.4711  Z=   0.0000
    starting width    0.0000
      ending width    0.0000

                  VERTEX    Layer: "0"
                            Space: Model space
                   Handle = 9E
                at point, X=  22.7211  Y=  14.1223  Z=   0.0000
    starting width    0.0000
      ending width    0.0000

                  END SEQUENCE  Layer: "0"
                            Space: Model space
                   Handle = [color=red]9F[/color]


Command: (handent "9a")
<Entity name: 7ef8cf10> [color=red];Plain ENTLAST returns last full entity (polyline)[/color]

Command: (handent "9f")
<Entity name: 7ef8cf38>  [color=red];KG:ENTLAST returns last subentity (END SEQUENCE)[/color]
[color=red];this avoids my XYZ_AFTER routine from grabbing an end sequence when the intent was to skip to the next full entity[/color]

« Last Edit: November 09, 2010, 03:25:15 AM by danallen »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: exclude entnext polyline subentities?
« Reply #4 on: November 09, 2010, 03:10:56 AM »
@ danallen: the last two red comments in your last post are in the wrong order, I think. :wink:

danallen

  • Guest
Re: exclude entnext polyline subentities?
« Reply #5 on: November 09, 2010, 03:26:23 AM »
@Roy - thanks again - I updated my comments, I hadn't had time to update my code and think through the logic.