Page 1 of 1

This code works, but then it doesn't??

Posted: Mon Mar 08, 2021 5:11 am
by sln8458
This is strange ???????

I have attached 2 lsp files, BLD & Piping & 2 'dim' files.

I have been working on the creation of Blind Flange blocks created on the fly rather than inserting them from a folder. I have completed the simple Flat Face & the Raised Face Blinds. The BLD code is for the Ring Type Joint faced Blind Flanges, which works as a stand alone routine. However when merged into the main Piping file the code fails during the 'insert' command??

Command window info
Command: _.-insert
[? to list blocks in drawing/BROWSE/EXPLORE]/<Block to insert> <BLRTJ_#150_18-3D>: BLRTJ_#150_18-3D
[Scale/X/Y/Z/Rotation/Multiple]/<Insertion point for block>: 0,0,0
[Corner/XYZ]/X scale factor <1.000000>:
Error: Function cancelled
So the strange thing is that I use the same code for inserting the created blocks??
If works for the Flat Face Flanges and works for the Raised Face Flanges but NOT the RTJ Flanges

Code: Select all

(defun INS_BLD ()
	(command "ucs" "ZA" INPT IANG)		
        (if (tblsearch "block" BLD1)
        (progn
        (command "_.-insert" BLD1 "0,0,0" insertscal "" "0"))
	); end IF
	(command "_ROTATE3D" "L" "" "X" "0,0,0" "270") 
	(command "ucs" "w" "")		
	(princ)
  )
Can anyone offer and suggestions pls
S.

Re: This code works, but then it doesn't??

Posted: Mon Mar 08, 2021 9:11 am
by QuanNguyen
Opps.
SLN_PIPING.png
SLN_PIPING.png (2.85 KiB) Viewed 5303 times

Re: This code works, but then it doesn't??

Posted: Mon Mar 08, 2021 9:53 am
by sln8458
Sorry,

DCL attached

Re: This code works, but then it doesn't??

Posted: Tue Mar 09, 2021 12:56 am
by QuanNguyen
Hi,
You're missing between the global variable and the local variable.
In the SLN_PIPING.lsp, you use the BLD1 as the local variable so after the function finishes running, the local variable value is automatically discarded, which means that the value of BLD1 will be NIL.

Please erase the BLD1 symbol in the definition of functions: FFBLD, RFBLD, RTJBLD then try again.
GlobalVariable.png
GlobalVariable.png (18.05 KiB) Viewed 5294 times

Re: This code works, but then it doesn't??

Posted: Tue Mar 09, 2021 2:09 am
by sln8458
Hi Quan,

Thanks for the info, unfortunately it has made no difference.

Code: Select all

(defun FFBLD (/ FFBLD:FOD$ FFBLD:RFTHK$ FFBLD:HOL$ FFBLD:HOD$ FFBLD:HPCD$ INPT IANG#); BLD1)

Code: Select all

(defun RFBLD (/ RFBLD:FOD$ RFBLD:FTHK RFBLD:RFD$ RFBLD:RFTHK$ RFBLD:HOL$ RFBLD:HPCD$ INPT IANG); BLD1)

Code: Select all

(defun RTJBLD (/ RTJBLD:FOD$ RTJBLD:FTHK RTJBLD:RTJD$ RTJBLD:RTJTHK$ RTJBLD:HOL$ RTJBLD:HPCD$ INPT IANG insertscal); BLD1 )
Command: _.-insert
[? to list blocks in drawing/BROWSE/EXPLORE]/<Block to insert> <BLRTJ_#150_18-3D>: BLRTJ_#150_18-3D
[Scale/X/Y/Z/Rotation/Multiple]/<Insertion point for block>: 0,0,0
[Corner/XYZ]/X scale factor <1.000000>:
Error: Function cancelled
Command: '_PMTHIST
S.

Re: This code works, but then it doesn't??

Posted: Tue Mar 09, 2021 2:39 am
by QuanNguyen
Try to remove the insertscal symbol in the definition of function RTJBLD.

Code: Select all

; Ring Type Joint Face Blind
(defun RTJBLD (/ RTJBLD:FOD$ RTJBLD:FTHK RTJBLD:RTJD$ RTJBLD:RTJTHK$ RTJBLD:HOL$ RTJBLD:HPCD$ INPT IANG BLD1 insertscal)
...
BTW, I can not debug your lisp, it needs more files.

Re: This code works, but then it doesn't??

Posted: Tue Mar 09, 2021 7:13 am
by sln8458
Thanks again Quan.

Which files do you need? I thought I had included enough

Re: This code works, but then it doesn't??

Posted: Tue Mar 09, 2021 10:07 am
by sln8458
SOLVED, I think :)

Quan, Your pointer helped, though it wasn't 'insertscal' that was the issue, but these three
ENT1, ENT2, ENT3.

I had used the same variable name in the 3 functions (declared as local), however the value for 'insertscal' popped up where ENT3 was expected??
Anyway re-named the variables as ENTFF1/2/3, ENTRF1/2/3 & ENTRTJ1/2/3 and it is all working as expected.

I don't understand why the cross pollination of variable values.
I thought that if they were declared local (/ var1 var2....) then they would be cleared when the function ends.
Still, lesson learnt, keep to unique variable names!!!!

S.