Jump to content

Recommended Posts

Posted

I have a small app that (with the help of those here) I have pieced together.

I don't know how to do add error checking (or conditionals) so that I don't get scrolling errors for the items that are not found.

 

Also, I think some of the items could be combined for my (ssget "x")

but I'm not clear on how that works either.

 

Requesting tweaking of my code or guidance.

 

Warning: I am still a novice...

 

Here is my code:

 

(DEFUN C:SW1 ()
(Prompt "SolidWorks DWG Cleanup:")

(setq TEST (tblsearch "LAYER" "Dim"))
    (if (= TEST nil)
            (progn
                 (Command "-layer" "n" "Dim" "C" "Red" "Dim" "")
            )
    )

(setq ss1 (ssget "x" '((0 . "INSERT")(2 . "*SW_CENTERMARKSYMBOL_*"))))
(Command "Erase" SS1 "")
(setq ss2 (ssget "x" '((0 . "INSERT")(2 . "*SW_NOTE_1*"))))
(Command "Erase" SS2 "")
(setq ss3 (ssget "x" '((0 . "INSERT")(2 . "*SW_TABLEANNOTATION_0*"))))
(Command "Erase" SS3 "")

(Command "-style" "Romans" "romans" "" "0.9" "" "" "n" "n")
(princ "\nRomans Text Style Created:")

(command "dimstyle" "r" "standard")
(command "dimtxsty" "romans")
(Command "dimstyle" "s" "standard" "y" )

 (if (setq ss (ssget "x" '((0 . "DIMENSION"))))
   (repeat
     (setq i (sslength ss))
      (setq sset (ssname ss (setq i (1- i))))
      (if (not (eq (cdr (assoc 3 (setq e (entget sset)))) "Standard"))
        (entmod (subst (cons 3 "Standard") (assoc 3 e) e))
      )
   )
   (princ)
 )

(setq ss4 (ssget "x" '((0 . "DIMENSION"))))
(Command "_CHANGE" SS4 "" "P" "LA" "DIM" "C" "BYLAYER" "")
(Command "_LAYER" "C" "GREEN" "X50" "C" "yellow" "TEXT" "")

(setq ss5 (ssget "x" '((6 . "PHANTOM"))))
(Command "_CHANGE" SS5 "" "P" "LA" "X25" "C" "BYLAYER" "LT" "PHANTOM" "")

(setq ss6 (ssget "x" '((6 . "HIDDEN"))))
(Command "_CHANGE" SS6 "" "P" "LA" "X25" "C" "BYLAYER" "LT" "HIDDEN" "")

(setq ss7 (ssget "x" '((6 . "DASHED"))))
(Command "_CHANGE" SS7 "" "P" "LA" "X25" "C" "BYLAYER" "LT" "DASHED" "")

(princ))

 

Thanks to all...

Posted

just some quick ideas to help you get started (but not tested)

you will find that most of the code you will write will be error checking

when you write a piece of code you should think about all the ways it can crash or cause problems.

typically a if statment can be used to verify but it all depends on what you are trying to do.

 

a overall error trap is always a good thing to learn so when the progran crashes all the settings are returned back to where thay where.

there are alot of error trap examples on this site just search for them

 

i hope this helps

 

 

 

 
(DEFUN C:SW1 ()
(Prompt "SolidWorks DWG Cleanup:")
(setq TEST (tblsearch "LAYER" "Dim"))
    (if (= TEST nil)
            (progn
                 (Command "-layer" "n" "Dim" "C" "Red" "Dim" "")
            )
    )
(setq ss1 (ssget "x" '((0 . "INSERT")(2 . "*SW_CENTERMARKSYMBOL_*,*SW_NOTE_1*,*SW_TABLEANNOTATION_0*"))))
(if ss1
(Command "Erase" SS1 "")
 );_if

;;;(setq ss2 (ssget "x" '((0 . "INSERT")(2 . "*SW_NOTE_1*"))))
;;;(Command "Erase" SS2 "")
;;;(setq ss3 (ssget "x" '((0 . "INSERT")(2 . "*SW_TABLEANNOTATION_0*"))))
;;;(Command "Erase" SS3 "")
;;; before you make a style use tblsearch to chaeck if it is there

(Command "-style" "Romans" "romans" "" "0.9" "" "" "n" "n")
(princ "\nRomans Text Style Created:")
;; also check for the below items
(command "dimstyle" "r" "standard")
(command "dimtxsty" "romans")
(Command "dimstyle" "s" "standard" "y" )
;****this is a good code usinf the if to error trap
 (if (setq ss (ssget "x" '((0 . "DIMENSION"))))
   (repeat
     (setq i (sslength ss))
      (setq sset (ssname ss (setq i (1- i))))
      (if (not (eq (cdr (assoc 3 (setq e (entget sset)))) "Standard"))
        (entmod (subst (cons 3 "Standard") (assoc 3 e) e))
      )
   )
   (princ)
 )
(setq ss4 (ssget "x" '((0 . "DIMENSION"))))
(if ss4 ;_us if to check if ss is good
(progn
(Command "_CHANGE" SS4 "" "P" "LA" "DIM" "C" "BYLAYER" "")
(Command "_LAYER" "C" "GREEN" "X50" "C" "yellow" "TEXT" "")
);_progn
 );_if
(setq ss5 (ssget "x" '((6 . "PHANTOM,HIDDEN,DASHED"))))
(if ss5
(Command "_CHANGE" SS5 "" "P" "LA" "X25" "C" "BYLAYER" "LT" "PHANTOM" "")
);_if
;;;(setq ss6 (ssget "x" '((6 . "HIDDEN"))))
;;;(Command "_CHANGE" SS6 "" "P" "LA" "X25" "C" "BYLAYER" "LT" "HIDDEN" "")
;;;
;;;(setq ss7 (ssget "x" '((6 . "DASHED"))))
;;;(Command "_CHANGE" SS7 "" "P" "LA" "X25" "C" "BYLAYER" "LT" "DASHED" "")
(princ)
);_defun

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