Search the Community
Showing results for tags 'reactor'.
-
reactor Reactor; CallBack func; error: Automation Error.
costin calin posted a topic in AutoLISP, Visual LISP & DCL
Hello, I have two reactor and two problems in callback functions. I have inserted same princ to be evident where is the error. Outside (from CallBack func reactors) they works properly. It seems that some LISP function are not compatibile to work in callback func (vlax-ename->vla-object, vla-update). My callback func.: - AppendBkAreaLst - when I copy an object included in _AreaBkLst, must add the new one to reactors : execution broke on line :(setq obL(vlax-ename->vla-object(entlast))) : message> 1 <Entity name: 1edac8b6420>2 ; error: Automation Error. Description was not provided. - CopyAreaBkReactor - when I modify a DynBlk parameters, update the area field attribute : execution broke on line: (vla-update ob) : message>!begin! ; error: Automation Error. Object was notifying : although, the field are updated, but report an error _AreaBkLst - global var - a lst with dyn blks ;------------Setup Reactors----------- (setq ModifyAreaBkReactor (vlr-object-reactor _AreaBkLst "ModifyAreaBkReactor" '((:vlr-modified . UpdateBkArea)))) (setq CopyAreaBkReactor (vlr-object-reactor _AreaBkLst "CopyAreaBkReactor" '((:VLR-copied . AppendBkAreaLst)))) ;------------Functions---------------- (defun AppendBkAreaLst (ob re Rlst / obL) ;at >COPY add new Blk to reactor /Callback fun (princ "1 ") (princ(entlast)) (princ "2 ") (setq obL(vlax-ename->vla-object(entlast))) (princ "3 ") (vlr-owner-add ModifyAreaBkReactor obL) (vlr-owner-add CopyAreaBkReactor obL) (princ)) (defun UpdateBkArea (ob re Rlst / ) ;when modify parameters- update area field /Callback fun (setq BC(BlockComponents (vla-get-name ob) "")) (setq obS(vlax-ename->vla-object (nth 5 bc))) (setq Area (vlax-curve-getarea(car BC))) (vla-put-TextString obS Area) (princ "\n!begin! ") (vla-update ob) (princ "ok")(princ)) (defun BlockComponents ( blk typ / ent lst ) ;lst all enteies inside blk (setq typ (strcat typ "*")) (if (setq ent (tblobjname "block" blk)) (while (setq ent (entnext ent)) (if (wcmatch (cdr (assoc 0 (setq enx (entget ent)))) typ) (setq lst (cons ent lst))))) (reverse lst))-
- fields
- dymamic block
-
(and 1 more)
Tagged with:
-
Hello! I'm performing a count in order to create a report from a dwg file. Counting functioncan be called at any time, but necessarily runs on close - when I also count the edit time. For that I'm using a reactor. That works fine. Prior to start the counting I'd like to overkill the whole drawing. That way it will not generate fake data due to duplicated objects. My code: (defun finalize ( / total_vector t_time) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vla-sendCommand doc "_.-overkill\r_all\r\r_done\r") (arxload "EDITTIME") (load "julian") (setq total_vector (jtoc (acet-edittime-total))) (setq t_time (strcat (LM:rtos (nth 3 total_vector) 2 0) ":" (LM:rtos (nth 4 total_vector) 2 0))) (acet-edittime-enable "OFF") (report1 t_time) (report2 t_time) (CloseReactor) ) As you can see, I'm using a few of (the marvelous) Lee Mac's functions too: (defun CloseReactor nil (vl-load-com) ;; Lee Mac ~ 14.04.10 ( (lambda ( data / react ) (if (setq react (vl-some (function (lambda ( reactor ) (if (eq data (vlr-data reactor)) reactor) ) ) (cdar (vlr-reactors :vlr-editor-reactor) ) ) ) (if (vlr-added-p react) (vlr-remove react) (vlr-add react) ) (setq react (vlr-editor-reactor data (list (cons :vlr-beginclose 'CloseCallBack) ) ) ) ) (princ (if (vlr-added-p react) "\n** Reactor Activated **" "\n** Reactor Deactivated **" ) ) react ) "Close-Reactor" ) (princ) ) (defun CloseCallBack (reactor arguments) (vla-put-ActiveSpace (setq doc (vla-get-ActiveDocument (setq acad (vlax-get-acad-object)) ) ) acModelSpace ) (vla-ZoomExtents acad) (vla-put-ActiveLayer doc (vla-item (vla-get-layers doc) "0" ) ) (vla-put-ActiveUCS doc (vla-add (vla-get-usercoordinatesystems doc) (vlax-3D-point '(0. 0. 0.)) (vlax-3D-point '(1. 0. 0.)) (vlax-3D-point '(0. 1. 0.)) "TempWord_UCS" ) ) (if (not (eq "" (vla-get-FullName doc))) (vla-saveas doc (vla-get-FullName doc)) ) (princ) (finalize) ) ;; rtos wrapper - Lee Mac ;; A wrapper for the rtos function to negate the effect of DIMZIN (defun LM:rtos ( real units prec / dimzin result ) (setq dimzin (getvar 'dimzin)) (setvar 'dimzin 0) (setq result (vl-catch-all-apply 'rtos (list real units prec))) (setvar 'dimzin dimzin) (if (not (vl-catch-all-error-p result)) result ) ) I'm using vla-sendfile to call the overkill because I can't use command inside a reactor. If I close the reactor in the begining of the finilize funcion, it closes the drawing before running through the whole function. But I realized that the overkill is being performed AFTER the report1 and report2 functions. That is a problem because report1 and report2 are the functions that generate the report. So, I'm guessing there's some sort of priority of vanilla lisp over vla functions. Is that right? Is there other way of performing this overkill whithout using vla-sendcommand or command? Thanks a lot.
- 6 replies
-
- vla-sendcommand
- overkill
-
(and 1 more)
Tagged with:
-
Hi, I need use (command ".save" pth) in my reactor for automatic back up after 30 minutes. But I can not figure out how to write this in Visual LISP. I want save current unsaved dwg to new file, but current dwg has to remain unchanged and still be active. Method (vla-saveAs doc) makes new file but makes active just this new file and close the old one. (vla-save doc) saves only without creating new file. Following code is a part of commandEnded callback reactor: (defun GM:createBackUp (cmd / doc pth) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (setq pth (strcat (getvar "TEMPPREFIX") (vl-string-right-trim ".dwg" (getvar "DWGNAME")) "_" (rtos (getvar "CDATE") 2 6) ".dwg")) (if (not (wcmatch cmd "QSAVE,SAVEAS")) (progn ;(command ".save" pth) ;;;!!!! (princ "\nCurrent drawing has been saved.")) (vl-file-copy (strcat (getvar "DWGPREFIX") (getvar "DWGNAME")) pth)) (princ (strcat "\nBackup \"" (getvar "DWGNAME") "\" has been created. (" pth ")"))) Thanks.
-
Hello, I have problem with command reactor. I want to dress up (add some blok, put viewport in specific layer) all new layouts created by command „layout“ with option „New“ or the „plus“ icon in layout list panel. How can I find out the event (new layout) is occured? And how can I get reference to this new layout? Any ideas? Command ended reactor to command "LAYOUT" fires everytime even the new layout is not created. Thanks for help and I'am sorry for my english Marek
-
Issue with calling a .NET LispFunction with a Reactor
ColinHolloway posted a topic in AutoLISP, Visual LISP & DCL
Hi All, I have just hit a wall with some code I am working on and wondered if anyone had seen a similar situation (and found a solution). I have written a .NET routine that I use to control which Ribbon Menu Tabs and Panels are visible based on arguments passed to the routine. This runs correctly in AutoCAD 2016 when I call it from the command line or from inside a lisp function or command. However when I call the .NET routine from a reactor it fails: Command: System.ArgumentNullException: Value cannot be null. Parameter name: key at System.Collections.Generic.Dictionary`2.FindEntry(TKey key) at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value) at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction) at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.InvokeLisp(); error: ADS request error EDIT: I have found that calling ANY command from a reactor fails e.g. (command "line" "0,0" "1000,1000") called by a reactor the error is: Command: ; error: AutoCAD command rejected: "line" Any and all thoughts greatly appreciated. Colin -
So I want to be able to set things inside functions when the command is called up in the command line. I tried using a command reactor. It works fine when it is outside of the function that I wanted for it to be activated but when I put it inside the function, it doesnt seem to be getting the values of the variables before the command is called up. so I have a simple function used for texting. (defun c:trec() (reactoron) (command "rectang") ) This is not the actual function I want to use in autocad but using this as my test. So this is my reactor which lives in reactoron. (defun reactoron() (vl-load-com) (vlr-command-reactor nil '((:vlr-commandWillStart . startCommand))) (vlr-command-reactor nil '((:vlr-commandEnded . endCommand))) (vlr-command-reactor nil '((:vlr-commandCancelled . cancelCommand))) (defun startCommand (calling-reactor startcommandInfo / thecommandstart) (setq OldLayer (getvar "CLAYER")) (setq thecommandstart (nth 0 startcommandInfo)) (cond ((= thecommandstart "TREC") (setvar "CLAYER" "4")) ) (princ) ) (defun endCommand (calling-reactor endcommandInfo / thecommandend) (setq thecommandend (nth 0 endcommandInfo)) (cond ((= thecommandend "TREC") (setvar "CLAYER" OldLayer)) ) (vlr-remove-all) (princ) ) (defun cancelCommand (calling-reactor cancelcommandInfo / thecommandcancel) (setq thecommandcancel (nth 0 cancelcommandInfo)) (cond ((= thecommandcancel "TREC") (setvar "CLAYER" OldLayer)) ) (vlr-remove-all) (princ) ) ) I should thank afralisp for the code sample which this code here is based from. So someone help me find a way to be able to activate this command reactor inside my function TREC?
- 9 replies
-
- autocad
- command reactor
-
(and 2 more)
Tagged with:
-
Hello, I am trying to get a LISP reactor to work whist a function is running. So my scenario is, is that I have I have a function that draws certain things in AutoCAD. While this function is running, I want to have my reactor activated, so it sets things and when the function is cancelled, the reactor will revert everything back to the way it was before I used the function in the command line. Right now, I have the function that draws stuff and a command Reactor. Can someone point me to the right direction on how to get the reactor to activate inside the function?
-
I want a command reactor to be able to activate inside a function however I am not sure if command reactors work with a user defined command or function. For an example, I want to be able to get the reactor to work on some (defun c:drawsomething () ....) and I want it to look for when the command drawsomething is called up? Can someone please point me in the right direction.
-
How do I have a command causes a function to
WPerciful posted a topic in AutoLISP, Visual LISP & DCL
I wrote a sub-routine to update drawing borders. There is a command in CADWorx called IGO which creates isometric drawings. I wanted have this command call my function which updates the borders. But my code doesn't work. (defun c:igo ( / ) (setvar "cmdecho" 0) (command "igo") (setvar "cmdecho" 1) (runisoborderupdate) (princ) ) -
Hi everyone! I just want to start by thanking you all, as most of the times I have an issue this forum is a great resource in which I find many answers without having to create a thread Since we use Acad 2014, some of my coworkers have started using viewbase style views. Since we have standards regarding lineweights, I've tried to find in vain a way to set the lineweight default values for the viewbase layers (MD_Annotation, MD_Hatching...) when CAD create them. Since i couldn't find any way to give them default values upon creation, my only option was to pre created on our templates all the layers generated by viewbase. The thing is that when someone purge a drawing prior to create the first viewbase, (which is 95% of the cases - designers make the design/3d model, purge, then the draftsman takes over the project to make the fab plans) the MD_ layers get deleted, and when they are generated again all the lineweights don't match our standards. From my perspective, I now have 2 options. 1- Beat the hell out of the designers whenever they purge the layers (which is not very nice..) 2- find a workaround (which I did, but I would need some help to achieve my goal since I'm not really acquainted with reactors) basically what I need is a reactor (in acaddoc.lsp i'd guess?) doing that: reactor@plot: verify if layers (MD_Annotation, MD_Hatching, MD_Hidden, MD_Visible) exist if not: resume plot if they do exist: check lineweight setting to ensure they match our standards (MD_visible = default, MD_hatching = .05mm, MD_hidden = .13mm, annotation=default) if true: plot if not: change values then plot If the MD_ layers do exist, i'm not sure if I should bother looking at their lineweight value to compare them with our standard, to change their value if they dont, or if I should directly set their lineweight value if the layers exist. Thanks in advance for your help Cheers, Jef!
-
Hi CAD lovers, Is it possible to distinguish between drawn objects (created by commands like: LINE, CIRCLE, ARC, ...) and constructed objects (created by commands like: OFFSET, FILLET (with radius), Chamfer (with distance), COPY, MIRROR (retaining source objects), ...)? Any help greatly appreciated.
-
Hi CADmates, as most of you know, CommandWillStart and CommandEnded are two reactors triggered just when a command called and a command ended. I am looking for a way to control OPEN command after selecting a drawing and before actually OPENing it. Is this mission possible? Any suggestions and help greatly appreciated.
- 7 replies
-
- open
- commandwillstart
-
(and 2 more)
Tagged with:
-
Hi, I recieve a number of drawings from outside the company. Not too suprissing they don't use that same printers, not to mention IT has a habit of changing print servers every couple of years. We have switched to using PC3 files which has helped some, but I'm still lef with a large set of legacy drawings that called for a physical printer. When AutoCAD start the print command for one of these drawings I get a message box that basicly says that the printer defined in the layout cannot be found and it is substituting the "None" printer. I don't know about you, but I would assume that if AutoCAD can't find the printer it's looking for that it should substitute something I can actually print to, you know... like a default printer?! Anyway... I have prgrammend a reactor to watch for the print command. When the plot cammand is called the LISP then checks the current plotdevice and comares it to a list specified in the LISP code. If a match is found then the rest of the code can be skipped, if no match then that means the currentplotdevice in the drawing is not one I use currently. If no match then the LISP overwrites the current plot device with a code defined "default", and then allow the plot command to continue. This eliminate the "error message" about not finding the plotter and substituting None printer. ;;; Check if the plotter last saved with the file is in a list of ;;; current devices. If it is not, change the plot device to a current ;;; device, If it is, leave things alone. ;;; (defun SwitchDefaultPrinter (/ Default ad OldPlotDevicee PlotDevices NonCurrentDevice) (setq Default "Black_Laser.pc3") ;Set default printer ;;create list of current plot devices (setq PlotDevices (list ;;Old System printers turned off ;;"\\\\bdn01ps001\\ccc_colorlaser" ;;"\\\\bdn01ps001\\color_laser" ;;"\\\\bdn01ps001\\drafting_lj8000" ;;"\\\\bdn01ps001\\drafting_plotter" ;;Current System printers turned off ;;"\\\\bdn01ps002\\ccc_colorlaser" ;;"\\\\bdn01ps002\\color_laser" ;;"\\\\bdn01ap010\\drafting_plotter" ;;"\\\\bdn01ps002\\ccc_upper_xerox_wc5755" ;;"\\\\bdn01ps002\\drafting_xerox_5550" ;Current PC3 Files "Black_Laser.pc3" "Color_Laser.pc3" "Drafting_Plotter.pc3" "DWG To PDF.pc3" ) ) (setq ad (vla-get-activedocument (vlax-get-acad-object))) ;;Set variable to hold reference to the active document (setq OldPlotDevice (GetActivePlotDevice ad)) ;;Set variable to hold reference to current plot device ;;comapre the old plot device to a list of current devices (if (= nil (vl-position OldPlotDevice PlotDevices)) (setq NonCurrentDevice 0) ;Device not found in list (setq NonCurrentDevice 1) ;Device found in list ) (if (= 0 NonCurrentDevice) ;if the current device is not in the current list of active devices. (progn (vla-put-ConfigName (vla-get-ActiveLayout ad) Default) ;;Change the plotter name to be used by the active layout (setq PrinterSwitched 1) ) ;;other wise leave it alone. ) (if (= nil (vl-position (vlax-get-property (vla-get-ActiveLayout ad) "StyleSheet") (GetPlotStyleTableNames ad) ) ) ;check the list of CTB files for the current requested CTB (vlax-put-property (vla-get-ActiveLayout ad) "StyleSheet" "Black_Laser.ctb" ;;Current CTB Not found, set CTB file to "Black_Laser.ctb" ) ;;Curerent CTB found, don't worry about it ) (if (= 1 PrinterSwitched) (progn (if (/= nil (vl-position "11x17" (GetCanonicalMediaNames ad))) ;;check list of paper sizes for 11X17 (vlax-put-property (vla-get-ActiveLayout ad) "CanonicalMediaName" "11x17" ;;11X17 found in the list of paper sizes, set paper size to 11x17 ) ;;11x17 is not in the list, don't worry about it ) (vlax-put-property (vla-get-ActiveLayout ad) "CenterPlot" -1 ) ;Set to center the plot on the paper (vlax-put-property (vla-get-ActiveLayout ad) "StandardScale" 0 ) ;Set to "Scale to Fit (vlax-put-property (vla-get-ActiveLayout ad) "PlotType" 1) ;Set to plot extents (vlax-put-property (vla-get-ActiveLayout ad) "PlotRotation" 1 ) ;Set to print Landscape ) ) (princ) ) (defun GetActivePlotDevice (ad) (vla-get-ConfigName (vla-get-ActiveLayout ad) ) ) (defun GetCanonicalMediaNames (ad) (vla-RefreshPlotDeviceInfo (vla-get-activelayout ad) ) (vlax-safearray->list (vlax-variant-value (vla-GetCanonicalMediaNames (vla-item (vla-get-layouts ad) "Model") ) ) ) ) (defun GetPlotStyleTableNames (ad) (vla-RefreshPlotDeviceInfo (vla-get-activelayout ad) ) (vlax-safearray->list (vlax-variant-value (vla-getplotstyletablenames (vla-item (vla-get-layouts ad) "Model") ) ) ) ) [\code] The problem is... this overwrite the currentplotdevice setting in the drawing. The boss doesn't like this. What I would like to be able to do is make this change, but when the plot command is finished, put back the old "currentplotdevice" so no real change to the cad file is made. I've got this by haveing the folling LISP run when the plot command is finished. [code] ;; Check to see if the printer was switched ;; If it was restore the old printer referenced in the file (if (= PrinterSwitched 1) (vla-put-ConfigName (vla-get-ActiveLayout ad) OldPlotDevice) ) [\code] The problem with this is that it always resets the "currentplotdevice" when the plot command is finished. If I press the "Apply to Layout" button in the plot dialog, I don't want the plot device changed after the plot command is finished. I haven't found a way for my reactor to "watch" for this button press. If I can "catch" this button press I can have the LISP change my variable 'PrinterSwitched' to "0" and this would skip the code to switch the currentplotdevice back, thus making things work the way I want. Sorry for the long post, but I hope I got all of the relevant info into it. Im running Windows 7 & AutoCAD 2012. Any advice and help is greatly appriciated. Thalon
-
- plot
- default printer
-
(and 1 more)
Tagged with:
-
Hi all, who knows a way to cancell a command via reactors Here is my code of traping event of starting commands. I want to prevent AutoCAD of continuing some commands, with no success: (VLR-Command-Reactor nil (list (cons :VLR-commandWillStart 'Reactor:commandWillStart ) ) ) (defun Reactor:commandWillStart (-calling-reactor- -info- / *cmdname*) (setq *cmdname* (read (car -info-))) (cond ((member *cmdname* '(STYLE DIMSTYLE DDIM )) [color=red][b](command); it doesn't work [/b][/color] ) (T (mapcar 'princ (list *cmdname* " will start."))) ) ) Any suggestion will be greatly appreciated
-
Hello every body, is it possibleto retain reactors attached to objects in dwg file, without running a program in subsequent sessions:unsure:?
-
All, I am looking for a way to create a reactor that changes a system variable back to specific variable when it is changed by a User or AutoCAD. Specifically i am talking about MLEADERSCALE, you might have noticed that if you have several styles and you switch between them your Mleaderscale resets to 1 or the specific scale set in the style. I set dimscale and mleaderscale the same and when that change happens mleaderscale ends up changing forcing me to reset the mleaderscale after each time the style is changed. I want to see the feasibility of using VLR-SysVar-Reactor and :VLR-sysVarWillChange and :VLR-sysVarChanged. I having trouble understanding the right code involved with these reactions. My furthest experience with VLR is just VLR-Command-Reactor's. objective: When Mleaderscale changes, it is reset to the current value of dimscale. Any help or nudge would be greatly appreciated, Matt
-
Let me state from the outset that I realise that there isn't too much practicality in this application, and hence I consider it more of a novelty app for your amusement and enjoyment. I have seen a few similar programs that will create a clock interface and proceed to animate the interface using a while loop or similar coupled with a small increment. These programs are cool in themselves, but take priority over all other user actions and also tend to lock up the average PC with all the entity regeneration. However, the engine that powers my application utilises a reactor to update it's display, and hence it may function in the background without hindering the actions of the user; moreover, it may be used as a functional timepiece whilst working. I have coded the program as a 'toggle', hence to initiate the clock, type 'clock' at the command-line, and similarly to disable the clock, type 'clock' again at the command-line. I hope you like it! Lee Clock.lsp DigitalClock.lsp