TRYING TO UNDERSTAND FUNCTION FOR SETTING PROPERTIES FOR CURRENTLY SELECTED OBJECTS

TRYING TO UNDERSTAND FUNCTION FOR SETTING PROPERTIES FOR CURRENTLY SELECTED OBJECTS

bchanlem
Explorer Explorer
308 Views
5 Replies
Message 1 of 6

TRYING TO UNDERSTAND FUNCTION FOR SETTING PROPERTIES FOR CURRENTLY SELECTED OBJECTS

bchanlem
Explorer
Explorer

IM NEW TO LEARNING HOW TO WRITE LSP FILES AND IM TRYING TO IDENTIFY AND UNDERSTAND HOW TO USE THE FUNCTION FOR SETTING PROPERTIES FOR A GROUP OF ITEMS SELECTED. FOR INSTANCE, AFTER SELECTING A GROUP OF XREFS, SETTING THEM ALL TO THE LAYER NAMED XREF_LAYER,  OR SETTING THEIR ROTATION TO 0. 

 

(defun RED21 ()
  (setq xref-keywords '("01" "02" "03" "04"))
  (setq color 21)

  (setq xrefs (vla-get-Xrefs (vla-get-ActiveDocument (vlax-get-acad-object))))

  (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-StartOpenCloseTransaction (vla-get-ActiveDocument (vlax-get-acad-object)))

  (foreach xref xrefs
    (setq xref-path (vla-get-Path xref))
    (setq xref-file-name (vl-filename-base xref-path))

    (foreach xref-keyword xref-keywords
      (if (vl-string-search xref-keyword xref-file-name)
        (progn
          (vla-Unload xref)
          (vla-Bind xref-path)
          (setq xref (tblsearch "BLOCK" (vlax-get-property (tblsearch "BLOCK" (vla-get-Name xref)) 'name)))
          (setq layers (vla-get-Layers xref))

          (foreach layer layers
            (vla-put-Color layer color)
          )

          (vla-Reload xref)
          (vla-Update xref)
        )
      )
    )
  )

  (vla-EndOpenCloseTransaction (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))

  (prompt "Layer colors in matching xrefs updated to color 21.")
)

; Call the routine
(RED21)

WOULD IT BE THE SAME ROOT COMMAND BECAUSE THOSE ARE ALL PROPERTIES OF THE OBJECTS OR DO NUMBER PROPERTIES (LIKE INSERT POINT, SCALE AND ROTATION) HAVE A DIFFERENT FUNCTION THAN PROPERTIES LIKE OBJECT LAYER NAME, COLOR AND STYLE?

0 Likes
309 Views
5 Replies
Replies (5)
Message 2 of 6

paullimapa
Mentor
Mentor

you can get a list of prop by entering the following at the command line & then select any object including XREFs:

(vlax-dump-object (setq obj (vlax-ename->vla-object(car(entsel)))))

 typically an XREF will return the following on the Text Screen:

Command: (vlax-dump-object (setq obj (vlax-ename->vla-object(car(entsel)))))

Select object:
; IAcadExternalReference: IAcadExternalReference Interface
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00007ff76bff3ea0>
;   Document (RO) = #<VLA-OBJECT IAcadDocument 000001ffdb3c9098>
;   EffectiveName (RO) = "Floor Plan Sample"
;   EntityTransparency = "ByLayer"
;   Handle (RO) = "13468"
;   HasAttributes (RO) = 0
;   HasExtensionDictionary (RO) = 0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 000001ffe90f5018>
;   InsertionPoint = (22421.5 -3037.97 0.0)
;   InsUnits (RO) = "Inches"
;   InsUnitsFactor (RO) = 1.0
;   IsDynamicBlock (RO) = 0
;   Layer = "0"
;   LayerPropertyOverrides (RO) = 0
;   Linetype = "BYLAYER"
;   LinetypeScale = 1.0
;   Lineweight = -3
;   Material = "ByLayer"
;   Name = "Floor Plan Sample"
;   Normal = (0.0 0.0 1.0)
;   ObjectID (RO) = 42
;   ObjectName (RO) = "AcDbBlockReference"
;   OwnerID (RO) = 43
;   Path = "C:\\Autodesk\\Floor Plan Sample.dwg"
;   PlotStyleName = "ByLayer"
;   Rotation = 0.0
;   TrueColor = #<VLA-OBJECT IAcadAcCmColor 000001ffe90f5310>
;   Visible = -1
;   XEffectiveScaleFactor = 1.0
;   XScaleFactor = 1.0
;   YEffectiveScaleFactor = 1.0
;   YScaleFactor = 1.0
;   ZEffectiveScaleFactor = 1.0
;   ZScaleFactor = 1.0
T

Like in your code, using the following will get the xref's layer name:

(vla-get-Layers obj)

The following will get the rotation in radians:

(vla-get-Rotation obj)

You can create a function like this to convert degrees to radians:

(defun Degrees->Radians (numberOfDegrees)(* pi (/ numberOfDegrees 180.0)))

Then to rotate the Xref by 90 degrees enter this:

(vla-put-Rotation obj (Degrees->Radians 90))

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant

@bchanlem wrote:

....

WOULD IT BE THE SAME ROOT COMMAND BECAUSE THOSE ARE ALL PROPERTIES OF THE OBJECTS OR DO NUMBER PROPERTIES (LIKE INSERT POINT, SCALE AND ROTATION) HAVE A DIFFERENT FUNCTION THAN PROPERTIES LIKE OBJECT LAYER NAME, COLOR AND STYLE?


For properties that you can change for a multiple-object selection collectively, such as with CHPROP or the Properties option in CHANGE, see Help for CHPROP.  I suspect [I haven't studied all possibilities] any other kinds of properties, such as those numerical ones you list, would need to be done on each object individually.

Kent Cooper, AIA
0 Likes
Message 4 of 6

bchanlem
Explorer
Explorer

sorry im a bit confused. youre saying this code  would tell me the rotation, insert point and scale but not edit them?  and the second bit of code would just rotate the object relative 90 degrees? not set the rotation to 90 degrees?

0 Likes
Message 5 of 6

paullimapa
Mentor
Mentor

Just remember that when you use code with "get" that means you're getting the current property settings.

When you use code with "put" that means you're changing the object

Best way for you to understand is to try it.

Just copy & paste each line of code into the AutoCAD command line & respond accordingly.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor

Like paullimapa some other methods use GET but use SET to change them, if your using Getproperty and Setproperty.

 

Help: setpropertyvalue (AutoLISP) (autodesk.com)

 

Another is when editing tables they use Set rather than Put.

 

Also there is ENTMOD try this on your xref (entget (car (entsel "\nPick xref "))) to show the dxf codes. Look at (50 . x) that is rotation.

0 Likes