Jump to content

How To Change and Objects Color With Vla????


BLOACH85

Recommended Posts

I have a routine that offsets on both sides that i have written but i want the line entity (original object) to change to a "cyan" color # 4

and the two outside lines to be a "yellow" #2 color. Does anyone know the correct syntax and variables to be used?

Link to comment
Share on other sites

Ok so ive tried it and im still pulling a syntax error here is the code the color and defualt values are all thats left that need to be fixed

Link to comment
Share on other sites

(defun c:bs (/ os cmd entity dist object keywrd)
(setq os (getvar "osmode"))
(setq cmd (getvar "cmdecho"))
(setvar "osmode" 0)
(setvar "cmdecho" 0)
 (while (not entity)
   (if (eq (setq entity (car (entsel "\nSelect line to offset:  ")))
    nil)
     (princ "\nThat was not a line.  Please select a line!:  ")))
 (initget (+ 1 2 4 64))
 (setq dist (getdist "\nEnter offset distance: [0.83/0.95] <0.83>  "))
 (initget (+ 2 4) "Yes No")
 (setq keywrd (getkword "\nDelete original object [Yes/No] <No>:  "))
 (if (/= keywrd "Yes")
   (setq keywrd "No"))
 (setq object (vlax-ename->vla-object entity)
)
 (vla-offset object dist)

 (vla-offset object (* dist -1)
   )
 (if (eq keywrd "Yes")
   (vla-erase object)
 )
 (setvar "osmode" os)
 (setvar "cmdecho" cmd)
 (princ)
)

Link to comment
Share on other sites

(defun c:bs (/ os cmd entity dist object nObj keywrd)
 (vl-load-com)
(setq os (getvar "osmode"))
(setq cmd (getvar "cmdecho"))
(setvar "osmode" 0)
(setvar "cmdecho" 0)
 (while (not entity)
   (if (eq (setq entity (car (entsel "\nSelect line to offset:  ")))
    nil)
     (princ "\nThat was not a line.  Please select a line!:  ")))
 (initget (+ 1 2 4 64))
 (setq dist (getdist "\nEnter offset distance: [0.83/0.95] <0.83>  "))
 (initget (+ 2 4) "Yes No")
 (setq keywrd (getkword "\nDelete original object [Yes/No] <No>:  "))
 (if (/= keywrd "Yes")
   (setq keywrd "No"))
 (setq object (vlax-ename->vla-object entity))
 [color="Blue"](vla-put-Color object 4)
 (setq nObj(car(vlax-safearray->list(vlax-variant-value(vla-offset object dist)))))
 (vla-put-Color nObj 2)
 (setq nObj(car(vlax-safearray->list(vlax-variant-value(vla-offset object(- dist))))))
 (vla-put-Color nObj 2)[/color]
 (if (eq keywrd "Yes")
   (vla-erase object)
 )
 (setvar "osmode" os)
 (setvar "cmdecho" cmd)
 (princ)
)

 

Offset method returns variant - array of the new objects.

Link to comment
Share on other sites

ASMI, You are the man now what i think that im beginning to understand what you did but thats about three more lines then what i had. If you dont mind could you explain a little?

Link to comment
Share on other sites

If you dont mind could you explain a little?

 

Ok. We will use command line. Draw a line. Pick it and transform to vla-object at once:

 

Command: (setq vline(vlax-ename->vla-object(car(entsel))))
Select object: #<VLA-OBJECT IAcadLine 0116a5f4>

 

Now apply offset method and save result into variable:

 

Command: (setq vrnt(vla-Offset vline 10.0))
#<variant 8201 ...>

 

Now you have Variant - data type which can contain any data. Look how data inside variant:

 

Command: (setq arr(vlax-variant-value vrnt))
#<safearray...>

 

It is safearray - matrix with data. Transform it to a list:

 

Command: (setq lst(vlax-safearray->list arr))
(#<VLA-OBJECT IAcadLine 0116a924>)

 

Ok it list with a new line. Extract it with car function and paint to the red:

 

Command: (vla-put-Color (car lst) 1)
nil

 

All done... Look for variants and arrays inside ActiveX functions here.

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