Jump to content

Recommended Posts

Posted

I am trying to write a code to extract the dimscale of an existing dimension by picking it.

I have tried using "assoc" without any results.

 

Any help will be welcomed

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • CAB

    8

  • ebrito

    7

  • Lee Mac

    6

  • CarlB

    1

Top Posters In This Topic

Posted

Give this a shot.

(defun c:dsf (/ ent obj)
 (vl-load-com)
 (and
   (or (setq ent (entsel "\nSelect dimension to get Scale Factor."))
       (prompt "\nNothing selected."))
   (setq obj (vlax-ename->vla-object (car ent)))
   (or (vlax-property-available-p obj 'ScaleFactor)
       (prompt "\nNo scale factor."))
   (print)
   (princ (vla-get-ScaleFactor obj))
 )
 (princ)
)

Posted

Thanks But I get this message after loading "error: extra right paren on input"

I tried to fix it without success.

Posted

The code should work as is - I have just tested it.

 

The error that you are encountering means there is an extra ")" - possibly one that you have accidentally typed?

Posted

You are right I missed the first "(" whwn copying.

Thanks a lot.

 

I modify your code to select a dimension "dimscale" and "layer" to have a lisp to place continued dimensions in the selected layer and dimscale, using the selected dimension as a base.

I tried several command combinations without successes.

I am new to lisp and all help is welcomed

(defun c:dlcon (/ ent obj)

(vl-load-com)

(and

(or (setq ent (entsel "\nSelect Base Dimension"))

(prompt "\nNothing Selected"))

(setq obj (vlax-ename->vla-object (car ent)))

(or (vlax-property-available-p obj 'ScaleFactor)

(prompt "\nNo scale factor."))

(print)

;(princ (vla-get-ScaleFactor obj))

)

(setq a (vla-get-ScaleFactor obj))

 

(setvar "dimscale" a)

(setq X (cdr (assoc 8

(entget (car ent)))))

(command ".layer" "set" X "")

;In this section I want to have a command to place continued dimensions

;in the selected layer and dimscale, using the selected dimension as a base.

;I tried several command combinations without successs.

 

(COMMAND "LAYER" "SET" "0" "")

(princ)

)

Posted

Are you trying to run the DIMCONTINUE command with user selections?

Or are you trying to select dimensions to update with layer & scale factor?

Posted

I am trying to run dimcontinue with user selections.

In other words to have continued dimensions with the "dimscale" of the selected dimension placed in the layer of such selected dimension.

Posted

See how this works for you. (Not perfect.)

(defun c:dlcon (/ ent obj)
 (vl-load-com)
 (if (and
       (or (setq ent (entsel "\nSelect Base Dimension"))
           (prompt "\nNothing Selected")
       )
       (setq obj (vlax-ename->vla-object (car ent)))
       (or (vlax-property-available-p obj 'ScaleFactor)
           (prompt "\nNo scale factor.")
       )
     )
   (progn
     (setq cds (getvar "dimstyle"))
     (setq clay (getvar "clayer"))

     (command ".-dimstyle" "restore" (vla-get-StyleName obj))
     ;;(setvar "dimscale" (vla-get-ScaleFactor obj))
     (setvar "clayer" (vla-get-Layer obj))
     (vl-catch-all-apply
              'vl-cmdf (list "._dimcontinue" "_S"))
     (while (> (getvar "CMDACTIVE") 0)
       (command pause)
     )
     (command ".-dimstyle" "restore" cds)
     (setvar "clayer" clay)
   )
 )
 (princ)
)

Posted

Yes it works, but the semicolons in :

;;(setvar "dimscale" (vla-get-ScaleFactor obj))

have to be erased in order to get de dimscale of the picked dimension.

The only issue that is not "perfect" is that the dimension has to be picked twice to start.

A very good feature is that, the dimensions can be continued to the side of the pick, regardless of the direction in which the original was drafted.

 

Thanks a lot I wish some day I´ll be able to write as "imperfect" as you.

Posted

What are to prompts at the command line when you enter dimcontinue as a command? And after you add one dimension with the command?

Posted

The only issue that is not "perfect" is that the dimension has to be picked twice to start.

 

I suppose you could do it like this:

 

(defun c:dlcon (/ ent obj)
 (vl-load-com)
 (if (and
       (or (setq ent (entsel "\nSelect Base Dimension"))
           (prompt "\nNothing Selected")
       )
       (setq obj (vlax-ename->vla-object (car ent)))
       (or (vlax-property-available-p obj 'ScaleFactor)
           (prompt "\nNo scale factor.")
       )
     )
   (progn
     (setq cds (getvar "dimstyle"))
     (setq clay (getvar "clayer"))

     (command ".-dimstyle" "restore" (vla-get-StyleName obj))
     (setvar "dimscale" (vla-get-ScaleFactor obj))
     (setvar "clayer" (vla-get-Layer obj))
     (vl-catch-all-apply
              'vl-cmdf (list "._dimcontinue" "_S" ent))
     (while (> (getvar "CMDACTIVE") 0)
       (command pause)
     )
     (command ".-dimstyle" "restore" cds)
     (setvar "clayer" clay)
   )
 )
 (princ)
)

Posted

CAB,

 

A quick question -

 

Upon dissecting your LISP - I cannot find any such

 

vla-get-...xxx

 

functions in the AutoLISP Reference Manual, only

 

vlax-get-property

 

How do you use these vla-get-xxx functions?

 

Cheers

 

Lee

Posted

At te command line the prompt are:

Command: _dimcontinue

Specify a second extension line origin or [undo/Select]

 

( autocad displays a dim line attached to the last placed )

 

Specify a second extension line origin or [undo/Select]

 

(If select is chosen, any dimension can be picked and it starts again fron that dimension)

Specify a second extension line origin or [undo/Select]

Select continued dimension:

Posted

Use this code to get the properties:

(defun c:dump (/ ent obj)
 (while (setq ent (entsel "\nSelect entity to get object data: "))
   (print)
   (setq obj (vlax-ename->vla-object (car ent)))
   (vlax-dump-object obj t)
   (vlax-release-object obj)
   (princ "\n")
 )
 (princ)
)

 

Here I selected a line:

Select entity to get object data: ; IAcadLine: AutoCAD Line Interface
; Property values:
;   Angle (RO) = 6.25243
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00ac8928>
;   Color = 256
;   Delta (RO) = (73.8932 -2.2736 0.0)
;   Document (RO) = #<VLA-OBJECT IAcadDocument 061ffce4>
;   EndPoint = (-21.5502 -543.097 0.0)
;   Handle (RO) = "B187"
;   HasExtensionDictionary (RO) = 0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 068c7ea4>
;   Layer = "LayerName"
;   Length (RO) = 73.9281
;   Linetype = "ByLayer"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   Normal = (0.0 0.0 1.0)
;   ObjectID (RO) = 106617208
;   ObjectName (RO) = "AcDbLine"
;   OwnerID (RO) = 105390096
;   PlotStyleName = "ByLayer"
;   StartPoint = (-95.4433 -540.823 0.0)
;   Thickness = 0.0
;   Visible = -1
; Methods supported:
;   ArrayPolar (3)
;   ArrayRectangular (6)
;   Copy ()
;   Delete ()
;   GetBoundingBox (2)
;   GetExtensionDictionary ()
;   GetXData (3)
;   Highlight (1)
;   IntersectWith (2)
;   Mirror (2)
;   Mirror3D (3)
;   Move (2)
;   Offset (1)
;   Rotate (2)
;   Rotate3D (3)
;   ScaleEntity (2)
;   SetXData (2)
;   TransformBy (1)
;   Update ()

 

Note that you can modify any Property that is not (RO) Read Only

by using (vla-put- obj).

You can get any of the properties.

Posted

Ahhh, That is fantastic CAB - I can see now the allure of VL over Common LISP - I suppose getting a property using VL is so much easier than going through the palava of DXF Group Tables... :mrgreen:

 

And thanks for the Link - very interesting reading on the two methods.

 

 

I'm sorry to bother you further, but, why do you have to use:

 

vlax-release-object

 

I have read the ACAD help file and understand that the object cannot be accessed through the variable assigned to it (hope thats correct), but surely the value of this variable is erased by localising it in the main function:

 

(defun c:dump (/ ent obj)

 

Just curious.. :whistle:

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