Jump to content

Simple Offset Routine


PDuMont

Recommended Posts

Hello All, I hope the new year finds you well.

 

While both of these routine "work", I am getting errors after running them.

I think it may be something obvious, but it's apparently not obvious to me.

 

I think I may be handling the foreach incorrectly.

 

Version #1:

 

(defun c:PLO (/ cmde doc sset ent)
 (defun *error* (msg)
   (if	(and msg
     (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
)
     (princ (strcat "\nError: " msg))
   )
   (if	cmde
     (setvar 'cmdecho cmde)
   )
   (if	doc
     (vla-endundomark doc)
   )
   (princ)
 ) ;_ end of defun
 
 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-startundomark doc)
 (setq cmde (getvar 'cmdecho))
 (setvar 'cmdecho 0)

 (if (setq sset (ssget '((0 . "circle") (40 . 0.05))))
   (progn
     (foreach ent (mapcar 'cadr (ssnamex sset))
(command "_.offset" "0.1" ent "0,0" "")
     ) ;_ end of foreach
   ) ;_ end of progn
 ) ;_ end of if
 (setvar 'cmdecho cmde)
 (vla-endundomark doc)
 (princ)
) ;_ end of defun
(vl-load-com)

 

This creates the offsets but I get errors "Unknown Command 0,0" and "Unknown Command PLO". Like it's going through the command sequence again.

 

 

 

Version #2

 

(defun c:PLO (/ cmde doc sset ent obj )
 (defun *error* (msg)
   (if	(and msg
     (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
)
     (princ (strcat "\nError: " msg))
   )
   (if	cmde
     (setvar 'cmdecho cmde)
   )
   (if	doc
     (vla-endundomark doc)
   )
   (princ)
 ) ;_ end of defun

 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-startundomark doc)
 (setq cmde (getvar 'cmdecho))
 (setvar 'cmdecho 0)

 (if (setq sset (ssget '((0 . "circle") (40 . 0.05))))
   (progn
     (foreach ent (mapcar 'cadr (ssnamex sset))
(setq obj (vlax-ename->vla-object ent))
(vla-Offset obj 0.1)
     ) ;_ end of foreach
   ) ;_ end of progn
 ) ;_ end of if
 (setvar 'cmdecho cmde)
 (vla-endundomark doc)
 (princ)
) ;_ end of defun
(vl-load-com)

 

This creates the offsets but I get "error: bad argument type: lentityp (0 (-3.41352 31.3948 0.0))"

 

Any help would be greatly appreciated.

Link to comment
Share on other sites

The problem with the first routine is that you have a list of should be removed since you want only entity names to iterate through.

eg:

(vl-remove-if 'listp(mapcar 'cadr (ssnamex sset)))

 

And update the codes to the second routine accordingly as well.

Link to comment
Share on other sites

FWIW, the efficiency could be improved, as looping over the same data three times is unnecessary when a single loop will suffice, e.g.:

(foreach ent (ssnamex sset)
   (if (= 'ename (type (cadr ent)))
       ...
   )
)

 

However, in general, the ssnamex function is known to be relatively slow in comparison to other methods of processing selection set entities.

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