Hi all,
i just dont know where is the error. Could somebody, please take a look and tell me where i am wrong.
(defun c:of()
(setq PDist(getreal"Pipe spacing is :"))
(setq Obj(entsel"Select closed loop area"))
(setq Mp(getpoint"Select where to offset:"))
(setq Hdist(/ Pdist 2))
(setq Multipl 1.5)
(setq First_Offset(* Pdist Multipl))
(command "offset" Hdist Obj Mp "Exit")
(princ)
(command "offset" First_Offset Obj Mp "Exit")
(command "OFFSETDIST" (* 2.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 3.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 4.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 5.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 6.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 7.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 8.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 9.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 10.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 11.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 12.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 13.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 14.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 15.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 15.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 17.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 17.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(princ)
(command "OFFSETDIST" (* 19.5 Pdist))
;******************Label Programming starts here***************************
(setq point1(getpoint"Select Label position:"))
(setq Txt_Size(getint"Text Height :"))
(setq Distance_Between_Texts(* 1.3 Txt_Size))
(setq Txt(getint"Circuit Number :"))
(command "Area" "Object" Obj)
(setq Txt1(getvar"Area"))
(setq Txt1(float(/ Txt1 1000000)))
(setq LL1(float (* LL Txt1)))
(setq Txt1(rtos Txt1 2 2)) ;transforms a value to the string
(setq Txt(rtos Txt))
(setq LL1(rtos LL1 2 0 ))
(setq Pdist(rtos Pdist))
(setq Txt1(strcat "Area: "Txt1" [m2]"))
(setq LL1(strcat "Loop Lenght: "LL1" [m]"))
(setq Txt(strcat "Circuit Number: "Txt" [/]"))
(setq Pdist(strcat "Pipe Spacing: "Pdist" [mm]"))
(command "._layer" "_M" "Loop Label" "") ;sets as current layer the layer Loop label
(setq point2 (list (car point1)(+(cadr point1)Distance_Between_Texts ) 0.0))
(command "Text" point2 Txt_Size 0 Txt1) ;Area
(setq point3 (list (car point2)(+(cadr point2) Distance_Between_Texts) 0.0))
(command "Text" point3 Txt_Size 0 LL1) ;Loop lenght
(setq point4 (list (car point3)(+(cadr point3) Distance_Between_Texts) 0.0))
(command "Text" point4 Txt_Size 0 PDist) ; Shifting distance
(setq point5 (list (car point4)(+(cadr point4) Distance_Between_Texts) 0.0))
(command "Text" point5 Txt_Size 0 Txt) ;Circuit number
(command "Line" point1 Mp "") ;line which connects Label with a loop
(princ))
)
Solved! Go to Solution.
Solved by scottbolton. Go to Solution.
A few things:
The code you posted has an extra right paren on input. Remove the final ).
Unless you're paid by keystroke, rationalise your code to look like this:
(command "_OFFSET" First_Offset Obj Mp "Exit")
(command "_OFFSET" (* 2.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 3.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 4.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 5.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 6.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 7.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 8.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 9.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 10.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 11.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 12.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 13.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 14.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 15.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 15.5 Pdist) Obj Mp "Exit"); should this be 16.5? ;
(command "_OFFSET" (* 17.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 17.5 Pdist) Obj Mp "Exit"); should this be 18.5? ;
(command "_OFFSET" (* 19.5 Pdist) Obj Mp "Exit"); do you need this? ;
All the keystrokes you've saved should allow you to put spaces between variables and functions, although this wouldn't stop your code from running - it just makes it easier to read.
I'd recommend (setq Txt_Size (getreal "Text Height :")) rather than (setq Txt_Size(getint"Text Height :")).
(setq LL1 (float (* LL Txt1))). What is LL and where is it's value set? That's where the code is crashing for me.
The last one is "Loop Lenght: ".
S
Hi,
tnx, i have finded out where was the problem. This is how it should look like
(defun c:of ()
(setq PDist (getreal "Pipe spacing is :"))
(setq Obj (entsel "Select closed loop area"))
(setq Mp (getpoint "Select where to offset:"))
(setq Hdist (/ Pdist 2))
(setq Multipl 1.5)
(setq First_Offset (* Pdist Multipl))
(command "offset" Hdist Obj Mp "Exit")
(command "offset" First_Offset Obj Mp "Exit")
(command "OFFSETDIST" (* 2.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 3.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 4.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 5.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 6.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 7.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 8.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 9.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 10.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 11.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 12.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 13.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 14.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 15.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 16.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 17.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 18.5 Pdist))
(command "offset" "" Obj Mp "Exit")
(command "OFFSETDIST" (* 19.5 Pdist))
;******************Label Programming starts here***************************
(setq point1 (getpoint "Select Label position:"))
(setq Txt_Size (getreal "Text Height :"))
(setq Distance_Between_Texts (* 1.3 Txt_Size))
(setq Txt (getint "Circuit Number :"))
(command "Area" "Object" Obj)
(setq Txt1 (getvar "Area"))
(setq Txt1 (float (/ Txt1 1000000)))
(setq LL (float (/ 1000 Pdist)))
(setq LL1 (float (* LL Txt1)))
(setq Txt1 (rtos Txt1 2 2)) ;transforms a value to the string
(setq Txt (rtos Txt))
(setq LL1 (rtos LL1 2 0))
(setq Pdist (rtos Pdist))
(setq Txt1 (strcat "Area: " Txt1 " [m2]"))
(setq LL1 (strcat "Loop Lenght: " LL1 " [m]"))
(setq Txt (strcat "Circuit Number: " Txt " [/]"))
(setq Pdist (strcat "Pipe Spacing: " Pdist " [mm]"))
(command "._layer" "_M" "Loop Label" "")
;sets as current layer the layer Loop label
(setq point2 (list (car point1)
(+ (cadr point1) Distance_Between_Texts)0.0))
(command "Text" point2 Txt_Size 0 Txt1) ;Area
(setq point3 (list (car point2)(+ (cadr point2) Distance_Between_Texts)0.0))
(command "Text" point3 Txt_Size 0 LL1) ;Loop lenght
(setq point4 (list (car point3)(+ (cadr point3) Distance_Between_Texts)0.0))
(command "Text" point4 Txt_Size 0 PDist) ; Shifting distance
(setq point5 (list (car point4)(+ (cadr point4) Distance_Between_Texts)0.0))
(command "Text" point5 Txt_Size 0 Txt) ;Circuit number
(command "Line" point1 Mp "") ;line which connects Label with a loop
(princ)
)
@scottbolton wrote:.... rationalise your code to look like this:
(command "_OFFSET" First_Offset Obj Mp "Exit")
(command "_OFFSET" (* 2.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 3.5 Pdist) Obj Mp "Exit")
(command "_OFFSET" (* 4.5 Pdist) Obj Mp "Exit")
....
Better yet, you can combine multiple commands in one (command) function:
(command
"_OFFSET" First_Offset Obj Mp ""
"_OFFSET" (* 2.5 Pdist) Obj Mp ""
"_OFFSET" (* 3.5 Pdist) Obj Mp ""
....
"_OFFSET" (* 19.5 Pdist) Obj Mp ""
); end command
[I find that actually spelling out "exit" doesn't work, but gives me an error. The <exit> in the prompt is a default that I need to use Space/Enter to get -- the fact that it's all lower-case may be a clue to that. But that may be version-dependent.]
And if you could count on the User always picking a point that would be beyond the next-to-last offset object in the same direction, you could make it even simpler, because you can re-use the same offset distance as many times as you want on the latest object:
(command
"_OFFSET" First_Offset Obj Mp "Exit"
"_OFFSET" Pdist
(entlast) Mp
(entlast) Mp
(entlast) Mp
....
""
); end command
But I don't suppose that's something you can count on. However, if the offsetting is inward and the shape is regular enough, you could find the middle of its bounding box and use that this way. Or if the offsetting is outward, you could calculate a point far enough away that you could use it this way.