- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, all.
I've tested all (or most) of the individual parts of the following code (which, upon pasting below, lost all of the indentation for some reason, so my apologies for the apparent bad formatting). Also attached the MLTT.lsp file, in case it would help...
When I run the command "MLTT", the command goes through and asks the user for the wall width (say, 6), but once that is chosen the program throws an error which I can't seem to fix:
Error: bad function: "WALLS_6IN_CLOSED"
It happens when the code calls the function MLStyleCreate for the first time (see in blue below).
Question: can't I provide a string to that function? Is there something wrong with the function setup below?
Super thanks in advance for any help!
; --------------------------------------------------------------------------------------------------
; ---------------------------------- Main User Commands --------------------------------------------
; --------------------------------------------------------------------------------------------------
; Dynamic width command call, TOP justification:
(defun C:MLTT ( / MyMLStyleName MyMLWidth MyMLJust)
; First, ask user for MLine width:
(setq MyMLWidth (MLWidthCall))
; Then set the remaining variables:
(setq MyMLStyleName (strcat "WALLS_" (itoa MyMLWidth) "IN_CLOSED"))
(setq MyMLJust 0) ; 0 = top, 1 = zero, 2 = bottom
; Start main function:
(MLStyleCreate (MyMLStyleName MyMLWidth MyMLJust))
)
;
; --------------------------------------------------------------------------------------------------
; ----------------------------- Core Functions (DO NO EDIT) ----------------------------------------
; --------------------------------------------------------------------------------------------------
;
; Ask user for MLine width:
(defun MLWidthCall ( / temp)
; check if MLWidth is set already (set it up otherwise):
(if (null *MLWidth*)
(setq *MLWidth* 6) ; change this integer to most commonly used
)
(initget 6) ; bit 4+2: allows only non-zero, positive integers
(if (setq temp (getint (strcat "\nEnter a positive non-zero integer for wall width <" (itoa *MLWidth*) ">: ")))
(setq *MLWidth* temp)
)
*MLWidth*
)
; Sets MLine style (create it if needed) and calls MLine command:
(defun MLStyleCreate (MyMLStyleName MyMLWidth MyMLJust / *error* OldEcho)
;Error happens before it gets to this point
; Setup the error function:
(defun *error* ( msg )
(if (not (member msg '("Function cancelled" "quit / exit abort")))
(princ (strcat "\nError: " msg))
)
(princ)
)
; Silent mode start:
(setq OldEcho (getvar "CmdEcho"))
(setvar "CmdEcho" 0)
; Only creates if the style does not yet exist:
(if (not (MLineStyleCheck (MyMLStyleName)))
(progn
(if
(dictadd
(cdar (dictsearch (namedobjdict) "ACAD_MLINESTYLE"))
MyMLStyleName
(entmakex
(list
(cons 0 "MLINESTYLE")
(cons 100 "AcDbMlineStyle")
(cons 2 MyMLStyleName) ; 2 = MLine style name
(cons 70 272) ; 70 = endcaps (272 = closed)
(cons 3 (strcat "Walls " (itoa MyMLWidth) "\" wide")) ; 3 = description
(cons 51 (* 90 (/ PI 180))) ; 51 = start angle in radians
(cons 52 (* 90 (/ PI 180))) ; 51 = end angle in radians
(cons 71 2) ; 71 = number of lines in style
(cons 49 (/ MyMLWidth 2.0)) ; 49 = first offset
(cons 62 256) ; 62 = first offset color (256 = Bylayer)
(cons 6 "BYLAYER") ; 6 = first offset linetype
(cons 49 (* -1 (/ MyMLWidth 2.0))) ; 49 = second offset
(cons 62 256) ; 62 = second offset color (256 = Bylayer)
(cons 6 "BYLAYER") ; 6 = second offset linetype
)
)
)
; if MyMLStyleName had to be created above:
(princ (strcat "\n:: MLine style \"" MyMLStyleName "\" has been created ::\n"))
)
)
)
; set MyMLStyleName active, justification, and scale:
(setvar "CMLStyle" MyMLStyleName)
(setvar "CMLJust" MyMLJust)
(setvar "CMLScale" 1)
; Draw MLine:
(MLineDraw)
; silent mode end:
(setvar "CmdEcho" OldEcho)
(princ)
)
; Check if multiline style already exists (returns nil if not):
(defun MLineStyleCheck (MyMLStyleName / MLStyleDict MLStyle)
(if (setq MLStyleDict (dictsearch (namedobjdict) "ACAD_MLINESTYLE"))
(while
(and MLStyleDict
(not
(setq MLStyle
(if
(and
(assoc 3 MLStyleDict)
(= (strcase (cdr (assoc 3 MLStyleDict))) (strcase MyMLStyleName))
)
(list
(strcase MyMLStyleName)
(cdr (cadr (member (assoc 3 MLStyleDict) MLStyleDict)))
)
)
)
)
)
(setq MLStyleDict (cdr(member(assoc 3 MLStyleDict)MLStyleDict)))
)
)
MLStyle
)
; Draw Mline:
(defun MLineDraw ( / CurrLayer MyLayer MyLayerColor MyLayerDesc)
; Set pre-function layer:
(setq CurrLayer (getvar "CLayer")) ;stores current layer in memory
; Set up new layer variables
(setq MyLayer "A-WALL")
(setq MyLayerDesc "Architectural walls")
(setq MyLayerColor 1)
; Create layer if needed, then set it current:
(if (not (tblsearch "layer" MyLayer)) ; Checks if MyLayer exists
; if not (= nil), then create it:
(progn
; using "Make" makes the new layer current:
(command "-.Layer" "Make" MyLayer "Description" MyLayerDesc MyLayer
"Color" MyLayerColor MyLayer "")
(princ (strcat "\n:: Layer \"" MyLayer "\" created ::\n"))
)
; if yes, then make it current:
(setvar "CLayer" MyLayer)
)
(command "MLine")
; Wait for the MLine command to end:
(while (> (getvar "CMDACTIVE") 0) (command pause))
; Set pre-function layer back:
(setvar "CLayer" CurrLayer)
)
Solved! Go to Solution.