Can't seem to add code to the lisp

Can't seem to add code to the lisp

s.vegmond
Participant Participant
953 Views
10 Replies
Message 1 of 11

Can't seem to add code to the lisp

s.vegmond
Participant
Participant

Hi everyone,

 

Noob here...

 

I've tried to find the solution to my problem for the better part of the weekend, but seem unable to find it, or any clues. 

 

This is the situation:

A collegue of mine, who is sadly no longer my collegue, wrote a piece of code that clean up a dxf-file exported by revit. The cleaned-up dxf-file is used by a laser to project lines on a floor-frame that is build in the factory.

My ex-collegue was asked to tranfer the code, and the basis knowledge of changing it, to me.

This was two months ago.

Last week i was tasked with added and tweaking some of the code, but i cant seem te add lines of code to the lsp-file in the visual studio application.

 

what happens is this:

1. I load the code in VS

2. I start debugging and connect it to a dxf file that is opened in autocad 2022

3a. the original code runs, without problems

3b. the code that had added lines gives the following error 'no function definition: DML_HERNOEM'

the function DML_HERNOEM does exist, it ran without my code additions.

 

this might be a hint: the DML_HERNOEM is the first function that is called in the main function.

 

both the main function and the funtion that 'doesn't exist' are given below.

 

any help would be much appreciated. thank you!!

 

 

(defun c:DML_vloeraanzicht (#type# /) ;functie vraagt 1 tekst variabele aanroep b.v. (c:DML_vloeraanzicht "K21")(c:DML_vloeraanzicht "OPG")
  (command "undo" "begin")
  (setvar "cmdecho" 0)
  (setq #DML_snap# (getvar "osmode"))
  (setvar "osmode" 0)
  (setq #hoogte_bakje# 0) ;hoogte bakje op de vloer
  (DML_HERNOEM) ;hernoemen van lagen  THIS IS WHERE THE ERROR OCCURS
  (DML_zetvloerwaardes) ;haalt de juiste hoogte waardes op aan de hand van het ingegeven type
  (DML_tekststijl) ;stel de tekststijl in en wijzig alle bestaande teksten naar deze stijl
  (DML_minmax) ;bepaal de linker onderhoek van de hoekkolommen
  (DML_lijnen) ;teken de lijnen door de vier hoeken
  (DML_verplaats -100 -100) ;verplaats de selectie naar het 0,0 coördinaat
  (command "zoom" "extents") ;test voor SJAAK  KAN UIT BIJ LIVE ZETTEN
  (DML_verwijder_vloerobjecten) ;verwijder objecten en hun lagen die we niet willen projecteren
  (DML_unitnummer_vloeraanzicht) ;zet de unit nummer in de linker onderhoek
  (DML_rotate) ;draai de unit 90°
  (DML_Laad_Blok) ;controleer of de eind blokken van de binnenwanden geladen zijn
  (DML_vind_muur_lijnen) ;ga op zoek naar de lijnen van de binnenwanden
  (DML_verschuif_Z) ;functie die de diversen lagen naar de juiste Z waardes opschuift
  (DML_Overkill) ;voegt lijnen etc samen
  (DML_hernoem_Laag) ;functie voor het hernoemen van de lagen voor naar gelang het bouwsysteem
  (DML_purge) ;opschonen van de tekening
  (DML_verplaats_nulpunt -217 +15) ;Correctie om de units t.o.v. het 0,0 coördinaat van de laser te verplaatsen
  (command "zoom" "extents")
  (setvar "osmode" #DML_snap#)
  (setvar "cmdecho" 1)
  (command "undo" "end")
  (command "saveas" "dxf" "16" "" "Y") ;het bestand opslaan als DXF en overschrijven bestaand
  (princ) ;schoon afsluiten
);einde functie DML_vloeraanzicht

(defun DML_HERNOEM () ;functie voor het hernoemen van lagen
  ;eerste deel maakt laag aan indien deze niet bestaat, 2e deel hernoemt de laag
  (command "-layer" "make" "28_Wanden_STR1_Exterior" "")
  (command "-rename" "Layer" "28_Wanden_STR1_Exterior" "02_Exterior_STR1")
  (command "-layer" "make" "28_Wanden_STR2_Exterior" "")
  (command "-rename" "Layer" "28_Wanden_STR2_Exterior" "02_Exterior_STR2")
  (command "-layer" "make" "28_Wanden_STR1_Interior" "")
  (command "-rename" "Layer" "28_Wanden_STR1_Interior" "03_Interior_STR1")
  (command "-layer" "make" "28_Wanden_STR2_Interior" "")
  (command "-rename" "Layer" "28_Wanden_STR2_Interior" "03_Interior_STR2")
  (command "-layer" "make" "01_Binnenwanden" "Color" 40 "" "") ;op deze laag worden de nieuwe binnenwanden getekend
  (command "-layer" "make" "01_Binnenwanden_start" "Color" 70 "" "") ;op deze laag worden de wand blokken geplaatst
  (command "-layer" "set" "0" "") ;zorgt ervoor dat laag 0 weer actief wordt
) ;einde functie DML_hernoem

 

 

0 Likes
Accepted solutions (2)
954 Views
10 Replies
Replies (10)
Message 2 of 11

Kent1Cooper
Consultant
Consultant

I don't see what could be causing that, but if you don't mind a suggestion, I find it very odd to make new Layers with a name you don't want, and then immediately rename them.  Also, since most are not assigned any properties for which having them current spares you the need to spell out the name again, they may as well be made with the New option, rather than Make.  And you can create multiple New Layers in one shot, with comma separators.  You can also combine multiple Layer operations in one Layer command.  You should be able to do this:

 

(defun DML_HERNOEM () ;functie voor het hernoemen van lagen
  ;eerste deel maakt laag aan indien deze niet bestaat, 2e deel hernoemt de laag
  (command "_.layer"
    "_new" "02_Exterior_STR1,02_Exterior_STR2,03_Interior_STR1,03_Interior_STR2"
    "make" "01_Binnenwanden" "Color" 40 "" ;op deze laag worden de nieuwe binnenwanden getekend
    "make" "01_Binnenwanden_start" "Color" 70 "" ;op deze laag worden de wand blokken geplaatst
    "set" "0" "" ;zorgt ervoor dat laag 0 weer actief wordt
  ); command
) ;einde functie DML_hernoem

 

But that probably will not eliminate your error....

 

EDIT:  Which lines did you add?

Kent Cooper, AIA
0 Likes
Message 3 of 11

s.vegmond
Participant
Participant

Hi Kent1Cooper,

 

Thank you for the reply. I am not sure what the reason was for my ex-collegue the write that particular piece of code in that way. If/when if learm more about it i'll check back and evaluate.

 

i also think it won't solve the error. thanks again.

 

kind regards,

 

Sjaak

0 Likes
Message 4 of 11

Kent1Cooper
Consultant
Consultant

@s.vegmond wrote:

.... 'no function definition: DML_HERNOEM' ....


That suggests that somehow the c:DML_vloeraanzicht command definition is not properly completed, which would mean the DML_HERNOEM definition is "inside" it, and being further down the line, has not yet been defined by the time it calls for that.  If that's true, it suggests a missing closing right parenthesis somewhere, but I didn't see anything.

 

Here's a grabbing-at-straws possibility:  Was the .lsp file ever edited in a word processor, rather than a plain-text editor?  That could result in some quotation marks being the "smart" kind that are different at the left and right ends of a quote, like this [little 6's vs, little 9's], rather than plain ASCII double-quote characters.  If any are, that could explain the issue -- some command or system variable or option name might not be really "ended," and the rest of the code gets buried in that until the next plain double-quote.  I don't see any that look that way, but it's possible that such a thing might exist in your .lsp file but could become a plain one when pasted into a code window here.

 

I can't test for that, not having all those other sub-routine definitions.  But try putting the DML_HERNOEM definition first in the file, and then loading it.  If my quotation-marks idea is correct, I expect that part will work, and you will get some other error further along.

Kent Cooper, AIA
0 Likes
Message 5 of 11

s.vegmond
Participant
Participant

Hi Kent,

 

That did somthing! Thank you!!

 

i moved the function DML_HERNOEM to just below the main function and started debugging again. This time the main function gave the same error, but at a different position/subfunction. it appears that functions after my code addition do no 'work' anymore.

 

This suggests that the code I added if the cause...

 

The code i added is given below. it is added IN a (previously) working subfunction. i've double checked the quotation marks, by retyping them. The amount of left and right parenthesis should be good.

 

What i try to do with this code is to put certain blocks (with "*paring*" in the block name) from certain layers (layer names starting with "A-GENM-*") in another layer and deleting the source layers. I've tried to do this by reusing/adapting some code from the lisp with a little help from otger forum/internet posts.

 

    ;blocks met *paring* in naam in betreffende layers selecteren - kan met ssget
    (setq #SparingSel# (ssget "_X" '(0 . "INSERT")(2 .  "*paring*")(8 . "A-GENM-*")))
    ;temp laag aanmaken tmp_LG_1
    (setvar tmp_lg "tmp_lg_sparing")
    (command "_layer" "m" tmp_lg "")
    ;selectie naar laag tmp_LG_1
    (command "_chprop" #SparingSel# "" "_LA" tmp_lg "")
    ;'oude' lagen weggooien/legen
    (setq #SelOld1# (ssget "_X" '(8 . "A-GENM*")))
    (DML_verwijder_objecten #SelOld1#) ;roep de functie verwijder objecten aan met een laag als argument

 

Is the error in this code?

 

 

0 Likes
Message 6 of 11

Kent1Cooper
Consultant
Consultant

@s.vegmond wrote:

....

What i try to do with this code is to put certain blocks (with "*paring*" in the block name) from certain layers (layer names starting with "A-GENM-*") in another layer and deleting the source layers. ....


If wanting to delete the source Layers means the Blocks in question are the only things on those Layers, consider using LAYMRG instead, to merge all the "certain Layers" into the "another layer."  That will both put the Blocks [which you will not need to select, and it won't even matter if there are none] on the new Layer, and delete the source Layers in the process.

Kent Cooper, AIA
0 Likes
Message 7 of 11

Sea-Haven
Mentor
Mentor

Should this be, doubtful that a variable tmp_lg exists.

 

(setvar tmp_lg "tmp_lg_sparing")

(setq tmp_lg "tmp_lg_sparing")

 

0 Likes
Message 8 of 11

s.vegmond
Participant
Participant

Hi Kent,
Thank you for your reply.
The blocks with "*paring*" in the block name can be divided over 3 layers, all of these layers start with "A-GENM-*" (* to be the wildcard for both block names and layer names).
It would have been nicer to have all relevant block on 1 layer, but currently i cannot control the way the DFX is exported.
As it is now, all three layers could contain 12 blocks each, with only 3 per layer having "*paring*" in the block name.
I was trying the use ssget to get this selectin. Did I do this correctly?

 

Hi Sea-Haven,
Thank you for you reply.
That seems to be an error on my part. I'll change the setvar to setq as stated in line 3 of your snippet.
Would this solve my overall problem?

 

Kind regards,

Sjaak

0 Likes
Message 9 of 11

Kent1Cooper
Consultant
Consultant

@s.vegmond wrote:

... i try to ... put certain blocks (with "*paring*" in the block name) from certain layers (layer names starting with "A-GENM-*") in another layer and deleting the source layers. ....
.... As it is now, all three layers could contain 12 blocks each, with only 3 per layer having "*paring*" in the block name. ....


The second quotation indicates that there are other Blocks [and possibly other kinds of things] on those Layers, which you don't want moved to the new Layer.  The first quotation suggests that you want to eliminate those other Blocks, since that would be the result of deleting their Layer.  Is that correct?  If so, LAYMRG is not the solution, because it would keep them, and move them to the other Layer along with the ones you want moved.

Kent Cooper, AIA
0 Likes
Message 10 of 11

john.uhden
Mentor
Mentor
Accepted solution

@s.vegmond 

I found one problem...

(setq #SelOld1# (ssget "_X" '(8 . "A-GENM*")))

should be

(setq #SelOld1# (ssget "_X" '((8 . "A-GENM*"))))

 After (ssget "x" should be a list of dotted pairs. not just one dotted pair.

John F. Uhden

0 Likes
Message 11 of 11

s.vegmond
Participant
Participant
Accepted solution

This was the solution!

 

I feel kinda stupid it was the parentheses, but happy it works. Thanks to all who participated.

 

;before:
(setq #SparingSel# (ssget "_X" '(0 . "INSERT")(2 .  "*paring*")(8 . "A-GENM-*")))
;changed:
(setq #SparingSel# (ssget "_X" '((0 . "INSERT")(2 .  "*paring*")(8 . "A-GENM-*"))))
;
;
;before:
(setq #SelOld1# (ssget "_X" '(8 . "A-GENM*")))
;changed:
(setq #SelOld1# (ssget "_X" '((8 . "A-GENM*"))))
0 Likes