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

#1
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.
Attachments
Piping.zip
(17.58 KiB) Downloaded 182 times

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

#4
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 5187 times

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

#5
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??

#8
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.
cron