Jump to content

Lisp Won't Continue to Next Step


ksperopoulos

Recommended Posts

I am just learning to write lisp and I wrote this basic function to erase any miscellaneous data that might be outside my drawing area, but it won't continue to the next command in the whole lisp routine. What am I missing to move to the next command in my lisp?

 

(COMMAND "ZOOM" "E")
(COMMAND "ZOOM" "SC" "0.75X")
(COMMAND "ERASE" (SSGET"X") "R")

Link to comment
Share on other sites

  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • ksperopoulos

    9

  • Tharwat

    4

  • BlackBox

    4

  • irneb

    2

I think I know this one.

 

Sorry if I am wrong this is my first attempt at answering a Lisp question

but you need a space follwing the command and option.

The space is interpreted as newline or pressing enter

 

"Zoom "

Link to comment
Share on other sites

Sorry Jeff, but that wasn't it. In the ERASE command, I have to make selection window(s) to remove the items that I don't want deleted. After I do this, the lisp stops and doesn't continue to the rest of commands within the lisp. Thanks for trying.

Link to comment
Share on other sites

First adjust your view in the acad dwg and try this .

 

(defun c:test (/ p1 p2 ss i sset s j e)
 (if
   (and
     (setq p1 (getvar 'vsmin))
     (setq p2 (getvar 'vsmax))
   )
    (progn
      (setq ss (ssget "_w" p1 p2))
      (repeat (setq i (sslength ss))
        (setq sset (cons (ssname ss (setq i (1- i))) sset))
      )
      (setq s (ssget "_x"))
      (repeat (setq j (sslength s))
        (if (not (member (setq e (ssname s (setq j (1- j)))) sset))
          (entdel e)
        )
      )
    )
    (princ)
 )
 (princ)
)

 

Tharwat

Link to comment
Share on other sites

FYI future reference (COMMAND "ERASE" (SSGET"X") "R") this asking for 2 selection inputs the "X" is all then asking for a seperate remove they are independant of each other. You probably can not use the "R" to remove objects from the ssget

 

eg (command "erase" "wp" "CP" "W") is 3 seperate requests being added together.

 

Also not sure Z E, zooms total area and then going 75% would not necessarily get rid of junk. The view method above would be a better way.

Link to comment
Share on other sites

The zoom extents is so I can see everything in the drawing file. The zoom to 75% backs the view out just a little bit. That way when I make a selection window I can get objects on the edges without panning around or zooming out manually.

 

Tharwat - thank you, but that does not allow me to make a selection window of what I want to keep. In my very little experience with lisps, I am working on putting this functionality in what you have. Is there not a way to use what I have and make it work (which is obviously a lot easier for a simple minded person like me to understand):D?

Link to comment
Share on other sites

 

Tharwat - thank you, but that does not allow me to make a selection window of what I want to keep. In my very little experience with lisps, I am working on putting this functionality in what you have. Is there not a way to use what I have and make it work (which is obviously a lot easier for a simple minded person like me to understand):D?

 

Hi ,

 

I think if you add only the zoom command to the routine it would work .

 

(COMMAND "ZOOM" "SC" "0.75X")

 

Or you can use the command zoom only and select two points and the routine would do the rest .

 

Good luck.

 

Tharwat

Link to comment
Share on other sites

Let me try to explain what I *believe* is happening....

 

Using this code as an example:

 

(COMMAND "ZOOM" "E")
(COMMAND "ZOOM" "SC" "0.75X")
(COMMAND "ERASE" (SSGET "X") "R")
[color=blue](command "._line")[/color] [color=teal]; <-- Added for illustration purposes[/color]

 

... When you run this code from VLIDE with Animate turned on (Debug menu > Animate), you will see that the code steps through this line BEFORE the Editor shows the selection set from which objects can be removed. The erase command is effective at allowing objects to be de-selected, however the code "doesn't continue" because it's already been passed over.

 

Hope this helps!

Edited by BlackBox
Animate clarification
Link to comment
Share on other sites

Give this a try:

 

(defun c:FOO  (/ ss keep all)
 (vl-load-com)
 (if (setq ss (ssget "_:L"))
   (progn
     ((lambda (i / e)
        (while (setq e (ssname ss (setq i (1+ i))))
          (setq keep (cons e keep))))
       -1)
     (mapcar
       'entdel
       (vl-remove-if
         '(lambda (e)
            (vl-position e keep))
         ((lambda (i ss / e)
            (while (setq e (ssname ss (setq i (1+ i))))
              (setq all (cons e all))))
           -1
           (setq ss (ssget "_x"))))))
   (prompt "\n** Nothing selected ** "))
 (princ))

Link to comment
Share on other sites

I'm actually not too sure why you need the ssget in the first place. The only time that is "necessary" is when you do something like in Tharwat's code.

 

Why not simply have:

(command "._ERASE" "_All" "_Remove")

Link to comment
Share on other sites

(command "._ERASE" "_All" "_Remove")

 

Will this get everything inside the drawings the same as (ssget"x")? I am trying to rid the drawing of any invisible items that are hanging out in la la land.

Link to comment
Share on other sites

I have to prepare my drawing files to post to an ftp site for a project I am working on. I am trying to strip them down to only show our piping. Sometimes some of the guys in our office have miscellaneous items that are way beyond the boundaries of the building that do not need to be shared for our coordination with other subcontractors. Sometimes I can see those items, and sometimes they are left over points or nodes that I can't see. With these invisible objects outside the building area, people are not able to do a zoom extents and get only the building. It is a smaller scale version of it. It is also messing up the files that we are using inside Navisworks and Revit. That is why I need to find a way to grab all of these items and delete them from our drawings before we post them. Hopefully this helps.

Link to comment
Share on other sites

Quite honestly.....I never thought of doing it that way. I may give that a try. Thanks for the suggestion.

Link to comment
Share on other sites

It's been the best choice for lots of users nowadays all over this forum. :)
I'd actually say "nowadays" is being a bit obtuse. I remember the first time someone told be to use it to cleanup drawings: must be nearly 20 years ago!

 

Anyhow, to ksperopoulos: You're using 2011 right? Have you looked at the command-line version of -purge (note the minus sign in front)? There's an option to purge Zero length entities and empty text. Even using erase all (which does what you're after) or even wblock will still leave some stuff like a line with length of 0.0.

 

Actually my boss has asked me to list everything which needs to be done as and when we receive drawings from outside. In this week, can you believe how deja-vu that felt? Well, under the list of "cleaning the drawing" I had the following (for our case in particular):

 

  • Remap other Consultants’ XRefs: If the issued drawing has XRefs from other consultants, this needs to be remapped to that current version (instead of the one which came with the issue). Also the cross-consultant XRef must not be saved as current anywhere. E.g. say a mechanical drawing XRefs an architectural plan, the architectural plan in the issue must not be saved to either the ME folder, nor to the AR folder. But the ME’s drawing needs to be modified so its XRef points to the current version of that file under the AR folder (or one of its sub-folders). This XRef has to be changed to an Overlay, if not already done so.
  • XRefs: Some files may have several XRefs contained in them. These XRefs need to be saved into the same (base) consultant’s folder where the issued drawing number is saved. The XRef needs to be re-mapped if not already working thus. Easiest way would be to modify the XRef path in the reference manager to omit the prefixed folder path. I.e. only having the filename and no folder path at all. All these XRef files also need to be cleaned through this same set of procedures.
  • Remove Architectural portions: If the consultant’s drawing contains a bound / inserted / exploded / copied version of the architectural drawing, this needs to be erased. If this cannot be easily done through isolating layers (or otherwise), then the consultant needs to be informed to issue such that this is possible. Note some form of correlation needs to be kept for referencing & positioning purposes. Usually the grid would be perfect for such. Change the layer of whatever’s used for such to be NoPlot … thus allowing for it to be seen but not printed when xrefed into one of our drawings.
  • Convert Vertical Objects: Not referring to objects going “upward”, but rather vertical products of AutoCAD such as Mechanical/MEP/Civil/Architecture/etc. These objects cause problems when mixing different versions, causing slowdowns (if not outright crashes) in any drawing they’ve touched (being xrefed into one, using any type of copy / insert from such, etc.). If we have a copy of such vertical (e.g. Architecture) these contain a command ExportToAutoCAD which converts such complex objects to normal AutoCAD entities. If we do not have the relevant vertical product (e.g. Mechanical Desktop), then the standard AutoCAD has an AECtoACAD command, though it would be much more bullet-proof to have the consultant use his vertical and run ExportToAutoCAD.
  • Set All to ByLayer: Everything inside the drawing needs to be set to ByLayer (at least colour, but preferably also line types, line weights and pen styles). The standard AutoCAD command SetByLayer can be used for this.
  • Change Z-Values: If the drawing is meant to be 2D, then all entities need to be modified so they don’t contain different Z values (note some drawings do have benefit as 3D, e.g. site contours for import to Revit). All Z values to be changed to 0.0. Either do this through the properties palette, or use one of the numerous lisp utilities available on the web.
  • Erase all Non-selectable: Some entities may be empty / blank / erroneous. To remove such turn all layers on, thaw & unlock. Zoom extents. Start the Erase command, type All to select everything, type R and select over everything by crossing from right-to-left to remove the selectable items. Press enter to have the non-selectable entities erased. Repeat this for each tab in the drawing, not just the Model tab. After this issue the LayerP command to reset the layer settings to original.
  • Purge Zero/Empty: With newer versions of AutoCAD the command-line version of purge (prefix with minus/hyphen: -PURGE) has 2 new options: “Zero-length geometry” and “Empty text objects”. These may be used as well as the above erase all non-selectable as they complement each other.
  • Purge Registered Applications: This can only be done through the command-line version of purge. Prefic the purge command with a minus/hyphen thus: -PURGE Then use the RegApps option to get rid of any such space- & speed hogging data. This may need to be repeated after performing the normal Purge and Audit.
  • Purge: All non-referenced blocks, text styles, line types, dimension styles, etc. needs to be purged out of the drawing. For this the normal Purge command is sufficient, but may also be done through the command-line version by prefixing a minus/hyphen to the purge command: -PURGE and then using the All option. Though such needs to be done until all nested items are also purged. This purge may need to be repeated after some of the following cleanups have been performed. It may become more efficient to do the purge as the last cleanup in the drawing.
  • Audit/Recover: Perform an Audit on the drawing, if this fails open the drawing through recover. Newer versions have a new command RecoverAll which will recover the DWG and all its XRefs. If this still does not fix all errors, then perform a WBlock of the drawing and select the “Entire drawing” option in the Write Block dialog box. Replace the DWG file with the new DWG created from WBlock.

That's as comprehensive as I could think of at the time.

Link to comment
Share on other sites

(command "._ERASE" "_All" "_Remove")

 

FYI - This doesn't allow me to proceed to the next command in the lisp routine either.

Link to comment
Share on other sites

(command "._ERASE" "_All" "_Remove")

 

FYI - This doesn't allow me to proceed to the next command in the lisp routine either.

 

That has already been (partially) explained, see post #8.

 

Furthermore, you're beating a dead horse... what happened to trying WBLOCK? :?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...