PDA

View Full Version : Need help with code


pt_zooropa
2008-06-24, 02:51 AM
Hi,
I am doing a small program and I'm having some problems. Does someone can help me resolve the code?

;;;***********************************************************************************
;;;;;;MAKE ALL LAYERS ON

(vl-load-com)
(setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
(setq theLayers (vla-get-layers acadDocument))
(vlax-for item theLayers (vlax-put-property item "LayerOn" ':vlax-true) )

;;;***********************************************************************************
;;;;;;CREATE LAYER TMF IN COLOR 10

(setq ln (getvar "clayer"))
(setq ss (ssget))
(if (= (tblsearch "layer" "TMF") nil)
(command "layer" "make" "TMF" "color" "10" "" "lt" "bylayer" """"))
(command "chprop" ss "" "la" "TMF" "ltype" "bylayer" "color" "bylayer""")
(setvar "clayer" ln)
(setvar "cmdecho" ce)
(princ)
)

;;;***********************************************************************************
;;;;;;MOVE ALL TO LAYER TMF COLOR 10

(vl-load-com)
(vlax-for blk (vla-get-blocks
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
(vlax-for obj blk
(vla-put-Layer obj "TMF")
(vla-put-Color obj 10)
)
)


;;;***********************************************************************************
;;;;;;ZOOM EXTENTS

(setq qa_ss_all (ssget "X"));setq

(if (/= qa_ss_all nil)
(progn
(command "_.ZOOM" "EXTENTS");command
);progn
);if

;;;***********************************************************************************
;;;;;;REMOVE ALL DIMENSIONS

(if (/= (setq ssdim (ssget "X" (list (cons 0 "DIMENSION")))) nil) (setq dexist 1) (setq dexist nil) )
(if (= dexist 1)
(progn
(command "erase" ssdim "")
(princ "\nAll Dimensions Removed")
)
(princ "\nNo Dimensions Found")
)


;;;***********************************************************************************
;;;;;;REMOVE ALL POINTS

(if (/= (setq sspt (ssget "X" (list (cons 0 "POINT")))) nil) (setq pexist 1) (setq pexist nil) )
(if (= pexist 1)
(progn
(command "erase" sspt "")
(princ "\nAll Points Removed")
)
(princ "\nNo Points Found")
)
(princ)
)

;;;***********************************************************************************
;;;;;;REMOVE HATCH

(if (/= (setq sshtch (ssget "X" (list (cons 0 "HATCH")))) nil)
(setq Hexist 1)
(setq Hexist nil)
)
(if (= Hexist 1)
(progn
(command "erase" sshtch "")
(princ "\nAll Hatching Removed")
)
(princ "\nNo Hatching Found")
)
(princ)
)

;;;***********************************************************************************
;;;;;;REMOVE SOLID

(if (/= (setq sssld (ssget "X" (list (cons 0 "SOLID")))) nil) (setq sexist 1) (setq sexist nil) )
(if (= sexist 1)
(progn
(command "erase" sssld "")
(princ "\nAll Solid Fill Removed")
)
(princ "\nNo Solid Fill Found")
)
(princ)
)

;;;***********************************************************************************
;;;;;;CHANGE ALL TEXT (MTEXT AND TEXT) TO ROMANS

(vl-load-com)
(vlax-for
ts
(vla-get-textstyles (vla-get-activedocument (vlax-get-acad-object)))
(if (not (eq (vla-get-Name ts) ""))
(vla-put-fontfile ts "ROMANS")
)
)


;;;***********************************************************************************
;;;;;;DO A CLEANE (AUDIT AND PURGE) AND SAVE TO CURRENT VERSION

(DEFUN NOECHO (/)
(SETQ CE (GETVAR "CMDECHO"))
(SETVAR "CMDECHO" 0)
(COMMAND "_.Undo" "_Begin")
) ;_ end of defun
;; ----
(DEFUN ECHOON (/)
(COMMAND "_.Undo" "_End")
(SETVAR "CMDECHO" CE)
(PRINC)
) ;_ end of defun
;; ----
(DEFUN AUDITFIX ()
(COMMAND "_.Audit" "_Yes")
(COMMAND "_.Regen")
) ;_ end of defun
;; ----
(DEFUN C:CLEANSAVE (/ CE)
;; ----
(DEFUN *ERROR* (MSG)
(IF
(OR
(/= MSG "Function cancelled")
(= MSG "quit / exit abort")
) ;_ end of OR
(PRINC (STRCAT "\n\tERROR : " MSG "\n"))
(PRINC)
) ;_ end of IF
(COMMAND "_.Undo" "End")
(COMMAND "_.U")
(IF CE
(SETVAR "CMDECHO" CE)
) ;_ end of IF
(PRINC)
) ;_ end of DEFUN
;; ----
(NOECHO)
;; ----
(AUDITFIX)
(COMMAND "_.QSave") ;|Revised for AutoCAD 2007|;
;; ----
(PRINC "\n\tDrawing Auditted and Saved\n\tin AutoCAD current format. \n") ;|Revised for AutoCAD 2007|;
(ECHOON)


See attachment
Thanks

Lions60
2008-06-24, 06:27 PM
Where is your problem occurring within the code? If you're not sure you can open it in VLIDE and under the Debug Tool bar menu select animate and then you can load and run the program and it will step through the program until it errors out then you will not at what part of the code to try and fix.

pt_zooropa
2008-06-24, 08:11 PM
Where is your problem occurring within the code? If you're not sure you can open it in VLIDE and under the Debug Tool bar menu select animate and then you can load and run the program and it will step through the program until it errors out then you will not at what part of the code to try and fix.
Thank you. I try to put this peace of code to work, but it has errors when i run in autocad.

kennet.sjoberg
2008-06-24, 11:09 PM
You can start to remove the extra right parenthesis ) at line :
20
74
91
105

and add a missing right parenthesis ) at the very last line :
166

then add after line 12 a missing variable ce
(setq ce (getvar "cmdecho"))


You may now be able to run the code, and start to debug, take care of variables and tune it up.

: ) Happy Computing !

kennet

pt_zooropa
2008-06-25, 12:14 AM
kennet
Thank you. I had made that but it still display error:
"Invalid linetype name.
< Funcao Concluida >Function cancelled; error: An error has occurred inside the
*error* functionAutoCAD variable setting rejected: "blipmode" nil
Enter loaded linetype name or [?] <CONTINUOUS>:
Invalid linetype name.
Enter loaded linetype name or [?] <CONTINUOUS>:
Enter name list of layer(s) for linetype "CONTINUOUS" <TMF>:
Enter an option
[?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck
/Unlock/stAte/Description/rEconcile]:"

Look file attach

kennet.sjoberg
2008-06-25, 07:18 PM
As you can see in your code there is no blipmode involved
so why do you get the "*error* function AutoCAD variable setting rejected: "blipmode" nil" ?

Because of that you have more functions and code in your AutoCAD environment that is not written with care.

Your error handler at the crash point want to reset the systemvariable blipmode
that is not the error handler in your code.

Please read the Sticky: Anatomy of an AUTOLISP file in this forum
especially my first, second and third beer.

There is no linetype "bylayer" when making a layer, change to "Continuous" at line: 16


: ) Happy Computing !


kennet

BTW your code in this post it is very unstable written, but it should work "if you walk the line" exactly as the code want, after changing line 16.

pt_zooropa
2008-06-25, 08:23 PM
There is no linetype "bylayer" when making a layer, change to "Continuous" at line: 16

How can i bypass that? Oh my god...i was blind.
Thank you!