Jump to content

Trying to change color to Lineweight and plot style


rcb007

Recommended Posts

I stumbled upon this routine which is simple enough I could follow. But I am having a hard time trying to figure out how to make (2) routines from this.

- One routine that will just change the lineweight of the selected layer object.

- Second routine which will change the plot styles of the selected layer.

 

(defun C:CHCOLPICK (/ lay col)
 (setq
   lay (cdr (assoc 8 (entget (car (nentsel "\nObject on Layer to assign color to: ")))))
   col (acad_colordlg (cdr (assoc 62 (tblsearch "layer" lay))) nil)
 )
 (command "_.layer" "_color" col lay "")
 (princ)
)

Any help would be great! Thank you.

Link to comment
Share on other sites

Using a bit of vl if you have a look at the properties, Plotstylename is one of them so can use a If = layername (vla-put-PlotStyleName lay "xxxx") test on a dwg with a couple of layers.

 

(setq  doc (vla-get-activedocument (vlax-get-acad-object))) ; open database
(vlax-for lay (vla-get-layers doc)
(vlax-dump-object lay)
)

 

Link to comment
Share on other sites

I think I understand, that the above code does for dumping all the variables. I guess, how do I properly place the variable within the routine?

 

(defun C:LWPICK (/ lay ps)
 (setq
   lay (cdr (assoc 8 (entget (car (nentsel "\nObject on Layer to assign plotstyle to: ")))))
   ;col (acad_colordlg (cdr (assoc 62 (tblsearch "layer" lay))) nil)
     ps ((vla-put-PlotStyleName lay "") nil)
 )
 (command "_.layer" "_color" ps lay "")
 (princ)
)

 

Link to comment
Share on other sites

1 hour ago, rcb007 said:

I think I understand, that the above code does for dumping all the variables. I guess, how do I properly place the variable within the routine?

 


(defun C:LWPICK (/ lay ps)
 (setq
   lay (cdr (assoc 8 (entget (car (nentsel "\nObject on Layer to assign plotstyle to: ")))))
   ;col (acad_colordlg (cdr (assoc 62 (tblsearch "layer" lay))) nil)
     ps ((vla-put-PlotStyleName lay "") nil)
 )
 (command "_.layer" "_color" ps lay "")
 (princ)
)

 

 

Perhaps like this?

 

(defun c:lwpick ( / adoc lay obj vlay)
  (while (null (setq obj (entsel "\nObject on layer to assign ploystyle to: "))) (princ "\nNothing selected"))
  (setq lay (cdr (assoc 8 (entget (car obj))))
	adoc (vla-get-ActiveDocument (vlax-get-acad-object))
	vlay (vla-item (vla-get-layers adoc) lay)
	)
  (vla-put-Color vlay <your_color>)
  (vla-put-PlotStyleName vlay <your_style_name>)
  )

 

If you inspect (vla-item (vla-get-layers adoc) "0") or any vla-object, you can see a full list of properties that you can modify by using vla-put-.

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...