ccowgill Posted December 9, 2010 Posted December 9, 2010 I have a lisp routine that contains several functions, from time to time, I need to make changes, or add additional functions, etc. Does anyone have any techniques to organize the file so I can easily get from one routine to another? right now, I'm just putting a list at the beginning that tells what line to jump to, but every time I add another function, I have to change every one of the lines (because it adds an additional line) Thanks, Quote
Lee Mac Posted December 9, 2010 Posted December 9, 2010 I use separate files - I find its easier to use windows' search utilities to find what you need Quote
ccowgill Posted December 9, 2010 Author Posted December 9, 2010 It is for my layerstate command, basically I have a bunch of functions that call a main function, providing a layer list and properties as the argument. I dont know if that would be the best practice for this particular program. Quote
Guest kruuger Posted December 9, 2010 Posted December 9, 2010 i do something like this: for example: 1. file kr:CON... - ilcludes all conversion function 2. file kr:BLK - include block function 3. file kr: DLG - dialog func. 4. file kr:SSX - selection set func. ..... then "join" all files to one library file and put it in support autocad CAD. kruuger Quote
BIGAL Posted December 10, 2010 Posted December 10, 2010 Like Kruuger I have a master lisp program that has lots of defuns and these are called from other lisps so you dont have to write the code again the master gets loaded as part of autoload, the others load as required. The master lisp has the defuns for consistency in what is being drawn layer settings, snaps, units etc so new lisps provide funcitionallity but the background is always the same. It is suprising how many times in a lisp you do the same half dozen steps so makes programming a bit quicker also. Maybe a description of defuns used at start of program. Quote
ccowgill Posted December 10, 2010 Author Posted December 10, 2010 Well that is the case, I have a very extensive setup for our Lisp routines, and I try to avoid coding anything twice. If it is necessary to call a function in more than one program, I typically move it out. However, this is slightly different. Basically this Lisp file contains a bunch of layer lists. I'd say at this point in time, there are about a dozen or so, with some of the lists having as many as 180+ layers, the entire file is over 2000 lines long. I'm just trying to find a better way to move around inside the program when layers need to be tweaked, or when new layer states need to be added. Perhaps I should just separate them all into their own separate lisp file and start their names all with a similar beginning so they are grouped together. It isnt very pretty, but I guess that is probably the only alternative. Quote
BlackBox Posted December 10, 2010 Posted December 10, 2010 It isnt very pretty, but I guess that is probably the only alternative. Chris, I second Lee's suggestion. I use separate files, and use VLIDE Projects to easily manage them, then compile the project to .FAS/.VLX as necessary. Note - I've posted this in detail before, but I fear that was lost (over at the blue and orange site that shall not be named). For example, for my team's tools, I create/maintain three categories of code (each having its own 'Project' in VLIDE): Personal Settings - Self explanitory; one for each user. Programming Tools - These are for me, mostly. These are all of my 'Toolbox' functions (sub-functions) which prevent duplication of code across my suite of tools. Production Tools - These are for all users, and also range in degree of complexity. Everything from simple keyboard shortcuts, Emailing Reports via Outlook (from AutoCAD), to AECC tools (Land Desktop) for quick Floodplain Surface creation, etc. I use a single load statement from ACADDOC.lsp to load our personal settings which includes conditional calls for subsequent tools. For example - 'Load Personal Settings' function (arbitrary names used): (defun c:LPS () ;; (load "programming_tools.fas") ;; ... Code for personal settings ;; (load "production_tools.fas") (princ)) Conditional load, to avoid the 'Would you like to save Drawing1.dwg?' prompt: (if (= 1 (getvar 'dwgtitled)) ; If drawing is named, (c:LPS)) ; Then load personal settings. (princ) [edit] I also do a lot of working with Layer States, and instead of using lists, I've automated the export of *.LAS files into a project directory, and at drawing open the layer states (if part of our standardized list, and found within the project) are automatically imported. Thus, if there's a change to the Utility Adjustments Layer State (for example), the user simply makes the necessary change, and with a keyboard shortcut re-saves it within the current drawing, and exports it to the pre-defined project folder. The next time a drawing is opened with this layer state, it is automatically over-written within that drawing based on what has been saved out to the project. [/edit] Hope this helps! Quote
ccowgill Posted December 10, 2010 Author Posted December 10, 2010 I also do a lot of working with Layer States, and instead of using lists, I've automated the export of *.LAS files into a project directory, and at drawing open the layer states (if part of our standardized list, and found within the project) are automatically imported. Thus, if there's a change to the Utility Adjustments Layer State (for example), the user simply makes the necessary change, and with a keyboard shortcut re-saves it within the current drawing, and exports it to the pre-defined project folder. The next time a drawing is opened with this layer state, it is automatically over-written within that drawing based on what has been saved out to the project. Hope this helps! how does that work with xrefs throughout multiple projects? anyway, I've never actually tried it, but there's a first time for everything, I'll give it a shot. The worst that can happen is it takes a little getting used to a new way of doing things. Eitherway, it makes for easier editing in the future. Quote
BlackBox Posted December 10, 2010 Posted December 10, 2010 (edited) how does that work with xrefs throughout multiple projects? There are myriad ways of accomplishing this. For example: Consider a milieu of vl-file-copy, read-line, vl-string-search, vl-string-subst, and write-line functions to replace either an old reference name, or temporary name (from a template *.LAS file), and replace it with the appropriate reference name based on your file naming convention. Another option would be to manually copy the layer states (*.LAS) into your project, from a similar one, and within notepad manually do a find a replace initially. Then there's a human level of QC up front, and then rely on the automated tool for updates only. Edited December 10, 2010 by BlackBox Typo Quote
ccowgill Posted December 10, 2010 Author Posted December 10, 2010 Well, I think what I have will work, I can use wild card characters to eliminate the xref issues that would be associated with *.LAS files. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;2010.11.04 Layer Setup by Christopher T. Cowgill ;; ;;Truecolor function by Fred Tomke (www.theswamp.org) ;; ;;Coding assistance provided by Opie, RobertB, and irneb (www.augi.com), ronjonp ;; ;;Original code simplification by alanjt (www.augi.com, www.theswamp.org) ;; ;;CTRL+G to goto Line) ;; ;;c:Pavtmrkglayerstate LAY-PavtMrkg ;; ;;c:createsanitaryprofilelayers LAY-Profiles ;; ;;c:createstormprofilelayers LAY-Profiles ;; ;;c:profilebaselayers LAY-Profiles ;; ;;c:PNPBaseLayerstate LAY-PNPBase ;; ;;c:SCDLayerstate LAY-SurveyControlData ;; ;;c:PNPMSLayerstate LAY-PNPInP ;; ;;c:roadbaselayers LAY-RoadBase ;; ;;c:surveybaselayers LAY-SurveyBase ;; ;;c:tinlayerstate LAY-Tin ;; ;;c:PnPFinalLayerState LAY-PNPFinal-Create ;; ;;c:CreatePnPLayers LAY-PNPFinal-Create ;; ;;c:logLayerState LAY-Log-Overall ;; ;;c:overallsiteplan LAY-Log-Overall ;; ;;c:createpresentationlayers LAY-Presentation ;; ;;c:CreateXsectionLayers LAY-XSection ;; ;;c:intersectionlayerstate LAY-InterSection ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;**************************************************************************************************************************************** (defun truecolor (uColor / oColor) (setq oColor (vla-getinterfaceobject acadObject "AutoCAD.AcCmColor.18")) (cond ((= (type uColor) 'INT) (vla-put-ColorMethod oColor acColorMethodByACI) (vla-put-ColorIndex oColor uColor) ) ((not (listp uColor)) nil) ((= (length uColor) 3) (vla-put-ColorMethod oColor acColorMethodByRGB) (vla-SetRGB oColor (car uColor) (cadr uColor) (last uColor)) ) ((= (length uColor) 2) (vla-SetColorBookColor oColor (car uColor) (cadr uColor)) ) ) ; cond ocolor ) ; truecolor ;;**************************************************************************************************************************************** (defun alllayerset (lst / listlayer name match) (command "linetype" "_load" "*" "acad" "") (command "-layer" "SET" "0" "") (setq listlayer (vla-get-layers acaddocument)) (foreach y lst (if (wcmatch (car y) "*`**") () (if (tblsearch "LAYER" (car y)) () (vla-add listlayer (car y)) ) ;_ end of if ) ;_ end of if ) ;_ end of foreach (vlax-for x listlayer (or (vl-position (setq name (strcase (vla-get-name x))) '("0" "DEFPOINTS")) (if (setq match (vl-remove-if-not (function (lambda (x) (wcmatch name (strcase (car x))))) lst ) ;_ end of vl-remove-if-not ) ;_ end of setq (mapcar (function (lambda (p v) (if v (vl-catch-all-apply (function vlax-put-property) (list x p v) ) ;_ end of vl-catch-all-apply ) ;_ end of if ) ;_ end of lambda ) ;_ end of function '(Freeze Color LineType Plottable Description Truecolor) (cdar match) ) ;_ end of mapcar ) ;_ end of if ) ;_ end of or ) ;_ end of vlax-for (setq name nil) (vla-regen acadDocument acAllViewports) ) ;_ end of defun (defun c:overallsiteplan (/ layerlist layerlist1 layerlist2) (setq layerlist '( ("*|*" :vlax-true) ) ) ;_ end of setq (setq layerlist1 '( ("*Prop Sanitary*" :vlax-false) ("*Prop Forcemain*" :vlax-false) ("*Prop Water*" :vlax-false) ("*|Property" :vlax-false ("*|ROW" :vlax-false ("Dim" :vlax-false 3) ("Text" :vlax-false 3) ("*Exist EP*" :vlax-true) ("*Prop EP*" :vlax-true) ) ) ;_ end of setq (alllayerset layerlist) (alllayerset layerlist1) ) ;_ end of defun (defun c:createpresentationlayers (/ layerlist acm) (setq layerlist (list (list "Hatch Water" :vlax-false nil nil nil nil (truecolor (list 0 174 255))) (list "Hatch Trees" :vlax-false nil nil nil nil (truecolor (list 127 255 0))) (list "Hatch Concrete" :vlax-false nil nil nil nil (truecolor (list 200 200 200))) (list "Hatch Grass" :vlax-false nil nil nil nil (truecolor (list 80 193 36))) (list "Hatch HMA" :vlax-false nil nil nil nil (truecolor (list 100 100 100))) (list "Hatch Gravel" :vlax-false nil nil nil nil (truecolor (list 174 100 0))) (list "Sign Yellow" :vlax-false nil nil nil nil (truecolor (list "PANTONE(R) color bridge CMYK EC" "PANTONE 116 EC")) ) ;_ end of list (list "Sign Blue" :vlax-false nil nil nil nil (truecolor (list "PANTONE(R) color bridge CMYK EC" "PANTONE 294 EC")) ) ;_ end of list (list "Sign Orange" :vlax-false nil nil nil nil (truecolor (list "PANTONE(R) color bridge CMYK EC" "PANTONE 152 EC")) ) ;_ end of list (list "Sign Red" :vlax-false nil nil nil nil (truecolor (list "PANTONE(R) color bridge CMYK EC" "PANTONE 187 EC")) ) ;_ end of list (list "Sign Green" :vlax-false nil nil nil nil (truecolor (list "PANTONE(R) color bridge CMYK EC" "PANTONE 342 EC")) ) ;_ end of list (list "Sign Brown" :vlax-false nil nil nil nil (truecolor (list "PANTONE(R) color bridge CMYK EC" "PANTONE 469 EC")) ) ;_ end of list (list "Sign Flourecent" :vlax-false nil nil nil nil (truecolor (list 175 255 0))) (list "Sign Purple" :vlax-false nil nil nil nil (truecolor (list "PANTONE(R) color bridge CMYK EC" "PANTONE 259 EC")) ) ;_ end of list ) ;_ end of list ) ;_ end of setq (alllayerset layerlist) ) ;_ end of defun Quote
Lee Mac Posted December 11, 2010 Posted December 11, 2010 There are myriad ways... Consider a milieu... Someone's been reading the dictionary lol Quote
BlackBox Posted December 13, 2010 Posted December 13, 2010 Someone's been reading the dictionary lol What's life without a bit a levity!? Quote
irneb Posted December 14, 2010 Posted December 14, 2010 Well, if you've got a huge LSP file with lots of defuns and want to quickly jump between them ... you can use other Lisp editors. E.g. Notepad++ or PSPad. They have the ability to collapse and expand sections of lisp (and other languages) so you end up with an outline type view (i.e. one defun per line). Unfortunately though you'll still need VLIDE for debugging. Quote
ccowgill Posted December 14, 2010 Author Posted December 14, 2010 I just went ahead and separated them all, then created a vlx file. Quote
Recommended Posts
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.