Jump to content

change objects to layer by choosing element colour?


jt6572

Recommended Posts

Hey all, 

I need to separate interface lines into two layers - cut and fill. both layers have different properties to help define them (ie; cut batter is solid line, fill is dashed. company standard....). 

 

I export to dwg from 12d, which if I don't use mapping for the interfaces, will show in dwg as is in 12d and the sections of the lines in cut have an element colour of red, those in fill are green. 

 

so what I would like to be able to do is have a lisp that selects all objects that are colour "red" (rather than by layer) and have them moved to a cut interface layer and for all properties to be by layer.... this also goes for all green objects that would be moved to the fill interface layer. 

 

trust me - I have tried absolutely everything in exporting from 12d and apart from using a method that leaves gaps in the interface/batter line, nothing works. 

 

I know I can use a smart select, but I would really like to be able to simply run the lisp and get it all done with the one command and my skills in this department are not quite up to this task!! 

 

would really appreciate any help. thank you! :) 

 

 

2023-01-04-12d Interface help.png

Link to comment
Share on other sites

Best results would require a sample drawing.

 

(defun c:test (/ ss)
  (if (not (tblsearch "layer" "CUT INTERFACE"))
    (entmake '((0 . "LAYER") (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 . "CUT INTERFACE") (70 . 0) (62 . 1)))
  )
  (if (setq ss (ssget "_X" '((0 . "LINE") (62 . 1))))
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (entmod (append (entget ent) (cons 8 "CUT INTERFACE")))
    )
  )
  (if (not (tblsearch "layer" "FILL INTERFACE"))
    (entmake '((0 . "LAYER") (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 . "FILL INTERFACE") (70 . 0) (62 . 3)))
  )
  (if (setq ss (ssget "_X" '((0 . "LINE") (62 . 3))))
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (entmod (append (entget ent) (cons 8 "FILL INTERFACE")))
    )
  )
  (princ)
)

 

Link to comment
Share on other sites

hey mhupp, 

thanks very much for your help. :)

 

okay, so with my limited knowledge, is it correct to say that what your lisp does is select everything that is autocad colour number 1 (red) and move it to a layer named "CUT INTERFACE", and likewise for colour 3 (green) to "FILL INTERFACE"? 

 

just trying it out and it creates the layers correctly, but the actual lines stay on the layer they are on. is it something to do with this line? 

 

  (if (setq ss (ssget "_X" '((0 . "LINE") (62 . 1)))) 

 

they actually come out as 3D Polylines. should "0. "LINE" " be 3dpolyline or something? Ive tried

 

3DPOLYLINE, 3D_POLYLINE 

 

to no avail, but again, I'm by no means in my league here!! 

 

Thanks again. :)

2023-01-04-12d Interface help 2.png

Edited by jt6572
Link to comment
Share on other sites

22 minutes ago, jt6572 said:

they actually come out as 3D Polylines. should "0. "LINE" " be 3dpolyline or something? Ive tried

 

3DPOLYLINE, 3D_POLYLINE 

 

to no avail, but again, I'm by no means in my league here!! 

Use this to look at the DXF codes of the objects you want to select. Hint: You can string them together separating them with commas: (0 . "LINE,CIRCLE,POLYLINE")

(defun c:dxflist (/ e)
  (cond	((setq e (car (entsel "\nPick something to see DXF data: ")))
	 (mapcar 'print (entget e '("*")))
	 (textscr)
	)
  )
  (princ)
)

If you don't want an object filter remove the (0 . "LINE") and it will select all items that are a certain color.

Edited by ronjonp
  • Like 1
Link to comment
Share on other sites

2 minutes ago, BIGAL said:

A possible quick fix

(0 . "LWPOLYLINE") is a 2d polyline

(0 . "POLYLINE") is a 3d polyline

 

So use (0 . "*LINE") will find both types.

That is a quick answer but hopefully the OP uses the code above to learn for themselves.

Link to comment
Share on other sites

hey everyone, 

sorry, work is getting in the way of my getting better at my job again.... 

 

thanks very much for your help - I do appreciate all replies. :)

I will try to get to this asap and will report back. most likely tomorrow morning.

Link to comment
Share on other sites

  • 1 month later...

Hey again everyone, 

apologies for the late reply. Ive been really busy doing incredibly boring work stuff.... 😐

Ive tried using all three of the line types (code in lower pane shows the original "LIINE") but I cant seem to get the objects onto the layers created. 

whenever I simply change to POLYLINE OR *LINE, I only get the CUT INTERFACE layer created, but no objects moved to it. 

 

I have run the dxflist lisp, and then experimented with changing the AcDb value, the "70.  0"  to "70.  8".....  I really dont know what to do next. 

 

Ive tried!! with the original lisp I can at least get both the CUT and FILL interface layers, but Im sad to report I just cant get any better result. 

 

I would just give up, but being able to do this would be a massive bonus for me as currently the only way to separate cut and fill interface lines in 12d is to have two separate lines that will always have a gap between them depending on the section separation of the function run to model them. and that looks sh1t!! 

 

Command: _appload fix.lsp successfully loaded.
Command:
Command:
Command: DXFLIST
Pick something to see DXF data:
(-1 . <Entity name: 1c238ea2aa0>)
(0 . "POLYLINE")
(330 . <Entity name: 1c238e9eb20>)
(5 . "376A")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "ACCESS RD 3 strs")
(62 . 1)
(6 . "Continuous")
(370 . 0)
(100 . "AcDb3dPolyline")
(66 . 1)
(10 0.0 0.0 0.0)
(70 . 8)
(40 . 0.0)
(41 . 0.0)
(210 0.0 0.0 1.0)
(71 . 0)
(72 . 0)
(73 . 0)
(74 . 0)
(75 . 0)

 

 

(defun c:test (/ ss)
  (if (not (tblsearch "layer" "CUT INTERFACE"))
    (entmake '((0 . "LAYER") (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 . "CUT INTERFACE") (70 . 0) (62 . 1)))
  )
  (if (setq ss (ssget "_X" '((0 . "LINE") (62 . 1))))
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (entmod (append (entget ent) (cons 8 "CUT INTERFACE")))
    )
  )
  (if (not (tblsearch "layer" "FILL INTERFACE"))
    (entmake '((0 . "LAYER") (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 . "FILL INTERFACE") (70 . 0) (62 . 3)))
  )
  (if (setq ss (ssget "_X" '((0 . "LINE") (62 . 3))))
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (entmod (append (entget ent) (cons 8 "FILL INTERFACE")))
    )
  )
  (princ)
)

 

Link to comment
Share on other sites

Hey BigAl, 

they are definitely 3d Polylines, but using "POLYLINE" wasnt doing the trick. Ive tried a few different terms in that area.... will give your suggestion a go. 

thank you! 

 

They are definitely 3d Polylines. Below is what I have, but all I can ever get is the layers created. none of the red or green lines move to them. 😕

 

(defun c:test (/ ss)
  (if (not (tblsearch "layer" "CUT INTERFACE"))
    (entmake '((0 . "LAYER") (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 . "CUT INTERFACE") (70 . 0) (62 . 1)))
  )
  (if (setq ss (ssget "_X" '((0 . "POLYLINE") (62 . 1))))
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
	  (entmod (subst (cons 8  "CUT INTERFACE") (assoc 8 (entget ent) (entget ent)))
    )
  )
  (if (not (tblsearch "layer" "FILL INTERFACE"))
    (entmake '((0 . "LAYER") (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 . "FILL INTERFACE") (70 . 0) (62 . 3)))
  )
  (if (setq ss (ssget "_X" '((0 . "POLYLINE") (62 . 3))))
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
	  (entmod (subst (cons 8  "FILL INTERFACE") (assoc 8 (entget ent) (entget ent)))
    )
  )
  (princ)
)

 

Edited by jt6572
Link to comment
Share on other sites

12 minutes ago, jt6572 said:

Hey BigAl, 

they are definitely 3d Polylines, but using "POLYLINE" wasnt doing the trick.

 

Is the layer locked? inside of a block?

 

maybe try subst instead of append.

 

(if (setq ss (ssget "_X" '((0 . "LINE") (62 . 1))))
  (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
    (setq line (entget ent))
    (entmod (subst (cons 8 "CUT INTERFACE") (assoc 8 line) line))
  )
)

 

Edited by mhupp
Link to comment
Share on other sites

hey mhupp, 

thanks heaps for your help. 

 

no, the layers aren't locked and are red (cut) and green (fill) respectively. although, more important is that the lines are all properties by layer.... 

 

trying yours now.... 

 

okay, so exploding all 3d Polylines into lines and using just LINE does put all red on cut and green on fill, but when I change all of the "line" entries to polyline, it goes back to only creating the layers. 

this could work, but exploding is another step and also gives a billion small lines and the linetype of the fill layer is dashed and wont look dashed. 

 

again, apologies for my limited lisp abilities (try saying that with a lisp!), but I dont understand why it wont work with POLYLINE? 

 

Here is what I tried (after using just LINE, which works....) 

 

(defun c:test (/ ss)
  (if (not (tblsearch "layer" "CUT INTERFACE"))
    (entmake '((0 . "LAYER") (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 . "CUT INTERFACE") (70 . 0) (62 . 1)))
  )
(if (setq ss (ssget "_X" '((0 . "POLYLINE") (62 . 1))))
  (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
    (setq line (entget ent))
    (entmod (subst (cons 8 "CUT INTERFACE") (assoc 8 polyline) polyline))
  )
)
  (if (not (tblsearch "layer" "FILL INTERFACE"))
    (entmake '((0 . "LAYER") (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 . "FILL INTERFACE") (70 . 0) (62 . 3)))
  )
(if (setq ss (ssget "_X" '((0 . "POLYLINE") (62 . 3))))
  (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
    (setq line (entget ent))
    (entmod (subst (cons 8 "FILL INTERFACE") (assoc 8 polyline) polyline))
  )
)
(princ)
)

 

Edited by jt6572
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...