Offset Multiple Polylines to (new or current) layer?

Offset Multiple Polylines to (new or current) layer?

djurk_haas
Advocate Advocate
1,702 Views
8 Replies
Message 1 of 9

Offset Multiple Polylines to (new or current) layer?

djurk_haas
Advocate
Advocate

Hello,

 

The lisp (quick1) from the post "Offset Multiple Polylines to (new or current) layer?" does almost everything I want except :

- I don't want the original polylines  to be deleted;

- I want to offset all the polylines that are one a specific layer.

  I have tried to add the code: (setq sset (ssget "X" '((0 . "*LWPOLYLINE")))) but this gives an error: bad argument type: lselsetp nil.

- I want automatically offset the polylines to a specific layer (e.g. test)

I have already have made some adjustment so that the offset distance always will be 1 and the direction is always out.

Tanks for the help!!

0 Likes
Accepted solutions (1)
1,703 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant

@djurk_haas wrote:

....

  I have tried to add the code: (setq sset (ssget "X" '((0 . "*LWPOLYLINE")))) but this gives an error: bad argument type: lselsetp nil.

....


For that part, quickly:

 

The code further down is looking for a selection set variable called simply ss, not sset.

Kent Cooper, AIA
0 Likes
Message 3 of 9

ВeekeeCZ
Consultant
Consultant
Accepted solution

djurk_haas wrote:

Hello,

 

The lisp (quick1) from the post "Offset Multiple Polylines to (new or current) layer?" does almost everything I want except :

- I don't want the original polylines  to be deleted;

 

// it's not by default, right?

If you want to make sure. maybe just because you've changed the setting of the OFFSET command before, you may use this:

 

(command "_.OFFSET" "_E" "_N") (command)

 

 

 

- I want to offset all the polylines that are one a specific layer.

 

// you may use this: (if the test layer not exists, create one)

 

(or (tblsearch "LAYER" "Test")
    (command "_.LAYER" "_New" "Test" ""))

(setq LAYER "Test")

...and comment out the section which let an user to set the layer. But you may want to keep the echo off, so you need to be little more careful.

 

;  (SetQ LAYER (GetVar "CLayer")

(setq ECHO (GetVar "CmdEcho"))
(SetVar "CmdEcho" 0)
	
;  (While
;  (ProgN
;  (SetQ TEMP (GetString (StrCat
;  "\nDestination layer?<"LAYER">:")))
;  (Cond
;  ((Eq TEMP "") Nil)
;  ((TblSearch "LAYER" TEMP) (SetQ
;  LAYER TEMP) Nil)
;  (T (PrinC "\nLayer not found."))
;  )))

 

 

 

- I want automatically offset the polylines to a specific layer (e.g. test)

 

// See THIS that layer is dxf code 8, so extend the ssget's filter:

 

(setq ss (ssget '((0 . "*POLYLINE") (8 . "MySpecificLayer"))))

 

 


 

0 Likes
Message 4 of 9

djurk_haas
Advocate
Advocate

Hello,

 

I have put the lisps Offset Multiple Polylines and PTEXORT together (00-FM_RM3.lsp).

Because of this forum It now does work the way I want it to work!

Thanks a lot for the help! 

Now I have tried to run the lisp in one my original drawings (RV CZE K X0000.dwg) but then I get an error:

: bad argument type: FILE nil

 

When I change the filename of the drawing to RV_CZE_K_X0000.dwg (subsitute the blanks for an underscore) it's working fine. But I don't want to change the name of all my drawings.

 

Is there a solution for this problem?

 

Thanks again.

 

0 Likes
Message 5 of 9

Kent1Cooper
Consultant
Consultant

@djurk_haas wrote:

... I have tried to run the lisp in one my original drawings (RV CZE K X0000.dwg) but then I get an error:

: bad argument type: FILE nil

....


I don't see anything in that code that calls for a FILE variable.  Could it be coming from within the  c:offsetmultiplepolylinestonewlayer  command?

 

Never mind that....  I get that message from the

 

  (princ "\n" fh)

 

part.  Try it this way:

 

  (princ (strcat "\n" fh))

 

And likewise, in this part [I combined into one line]:

 

  (princ (strcat (rtos (car pnt) 2 8) "," (rtos (cadr pnt) 2 8) "," (rtos (caddr pnt) 2 8)) fh)

 

the 'fh' is outside the (strcat) function -- try:

 

  (princ (strcat (rtos (car pnt) 2 8) "," (rtos (cadr pnt) 2 8) "," (rtos (caddr pnt) 2 8) fh))

Kent Cooper, AIA
0 Likes
Message 6 of 9

djurk_haas
Advocate
Advocate

Kent,

 

I tried your option but it keeps given me the error  bad argument type: FILE nil

 

Any other ideas?

0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant

@djurk_haas wrote:

.... 

I tried your option but it keeps given me the error  bad argument type: FILE nil

Any other ideas?


The message means that at some place where it's expecting to be given a FILE to work with, it's not being given anything.  That could only mean [I think] that one of these lines is failing:

     (setq fn (strcat (getvar 'DWGPREFIX) (vl-string-subst "txt" "dwg" (getvar 'DWGNAME))))


     (if (/= fn nil)

       (progn

         (setq fh (open fn "w"))

 

I didn't get that error message when I used the (strcat) corrections suggested in Post 5, though I didn't work through the entire operation -- just enough of it to get to where the error message would be triggered if there was a failure.

 

If the first line is failing, that would mean 'fn' would be nil, and it would not set 'fh', but  it would also never get to the point of trying use  what's in the 'fh' variable and trigger that error.  So it's hard to imagine that the first line is what's failing.  That should  produce a valid result in any drawing, anyway, which should mean that 'fn' would not be nil, so the routine would get to the attempt to set the 'fh' variable, and that therefore looks like it should be the problem -- the setting of 'fh' must be returning nil, in order for that error message to occur from later attempts to use  the file that's supposed to be in the 'fh' variable.

 

Is the current drawing's folder location restricted in some way that would mean it will not be permitted to open a file in it?  That's about the only thing I can think of that might cause this problem.

Kent Cooper, AIA
0 Likes
Message 8 of 9

djurk_haas
Advocate
Advocate

Kent,

 

You said that it's hard to imagine that the first line (see red line below) is causin the error but I think that's yet using the error because when I comment out that redline and use the code in green (dialoog for saving) instead the lisp is just working fine.

 

 


     ;opslaan als met dialoog:
     (setq fn (getfiled "Point Export File" "" "txt" 1))
     ;direct opslaan in directory van dwg en met naam van de tekening:
    ; (setq fn (strcat (getvar 'DWGPREFIX) (vl-string-subst "txt" "dwg" (getvar 'DWGNAME))))
    

 

Thanks you in advance

0 Likes
Message 9 of 9

Kent1Cooper
Consultant
Consultant

Both those approaches give results that look equivalent:

 

Command: (setq fn (strcat (getvar 'DWGPREFIX) (vl-string-subst "txt" "dwg" (getvar 'DWGNAME))))
"X:\\my\\file\\path\\MyDrawingName.txt"
Command: (setq fn (getfiled "Point Export File" "" "txt" 1))
"X:\\my\\file\\path\\testing.txt"

 

[with the difference that I had to type in the file name in the second one.]  So I don't see why the one that builds the name based on the drawing name wouldn't work as well as the type-your-own-name one does, unless  perhaps when you do the latter and it works, you're not using the current drawing's folder, and that's restricted  in some way so that the (open) function can't put a file in it.

Kent Cooper, AIA
0 Likes