Jump to content

Recommended Posts

Posted

Hello,

 

I need code that will scale result for area of polyline by 0.0001 and length by 0.01.

 

Can anyone write this for me please?

Posted

welcome to the forum .

 

Do you mean that you want the area to be divided on 0.0001 and the length by 0.01 ?

Posted

Maybe ... :unsure:

 

(defun c:TesT (/ ss v) (vl-load-com)
 (print " Select Polyline :")
 (if (setq ss (ssget "_+.:S" '((0 . "*POLYLINE"))))
   (progn
     (setq v (vlax-ename->vla-object (ssname ss 0)))
     (alert
       (strcat (strcat "Total Length :"
                       "  "
                       (rtos (/ (vla-get-length v) 0.0001) 2))
               "\n"
               (strcat "Total Area   :"
                       "  "
                       (rtos (/ (vla-get-area v) 0.01) 2))
       )
     )
   )
   (princ)
 )
 (princ)
)

Tharwat

Posted

thank you for welcoming, and thank you for the code, but i didnt succeeded to implement it :(

 

what i want is that area of polyline is showen 10 000 times less (or 0.0001 larger) and length 100 times (or 0.01) in properties or in insert field option in tables. and the reason is because i draw in centimeters but i need to read area and length in meters.

 

anyway, i loaded code you gave me, but program is still showing me area and length in original form. did i missed something?

Posted
what i want is that area of polyline is showen 10 000 times less (or 0.0001 larger) and length 100 times (or 0.01) in properties or in insert field option in tables. and the reason is because i draw in centimeters but i need to read area and length in meters.

 

When creating the Field:

 

 

  • Type FIELD at the command-line

 

  • Choose 'Objects' from the Field Category drop-down.

 

  • Choose 'Object' from the Field names list-box.

 

  • Click the selection button and select your object.

 

  • Select the 'Area' property.

 

  • Click on the 'Additional Format' button.

 

  • Use a Conversion Factor to display the result as required.

Posted

@lee mac

 

i am doing that, but it takes me too long when i have to do it 200 times per project. that is why i am looking for a way to automatize it.

Posted
i am doing that, but it takes me too long when i have to do it 200 times per project. that is why i am looking for a way to automatize it.

 

Perhaps you should have explained in your earlier posts that you were actually creating fields and already using the Conversion Factor, and that this was the process that you wanted to automate.

 

The more information that you provide about your problem, the less time is wasted trying to ascertain what you are trying to accomplish.

 

Anyway, here is a very simple code snippet for you to study:

 

[color=RED]([/color][color=BLUE]defun[/color] c:test [color=RED]([/color] [color=BLUE]/[/color] doc ent format obj pt [color=RED])[/color] [color=red]([/color][color=blue]vl-load-com[/color][color=red])[/color]

   [color=RED]([/color][color=BLUE]setq[/color] format [color=#a52a2a]"%lu2%ct8[0.0001]"[/color][color=RED])[/color] [color=#990099];; Field Formatting Code[/color]

   [color=RED]([/color][color=BLUE]while[/color]
       [color=RED]([/color][color=BLUE]progn[/color] [color=RED]([/color][color=BLUE]setvar[/color] [color=DARKRED]'[/color]ERRNO [color=#009900]0[/color][color=RED])[/color] [color=RED]([/color][color=BLUE]setq[/color] ent [color=RED]([/color][color=BLUE]car[/color] [color=RED]([/color][color=BLUE]entsel[/color][color=RED])))[/color]
           [color=RED]([/color][color=BLUE]cond[/color]
               [color=RED]([/color]   [color=RED]([/color][color=BLUE]=[/color] [color=#009900]7[/color] [color=RED]([/color][color=BLUE]getvar[/color] [color=DARKRED]'[/color]ERRNO[color=RED]))[/color]
                   [color=RED]([/color][color=BLUE]princ[/color] [color=#a52a2a]"\nMissed, try again."[/color][color=RED])[/color]
               [color=RED])[/color]
               [color=RED]([/color]   [color=RED]([/color][color=BLUE]eq[/color] [color=DARKRED]'[/color]ENAME [color=RED]([/color][color=BLUE]type[/color] ent[color=RED]))[/color]
                   [color=RED]([/color][color=BLUE]if[/color]
                       [color=RED]([/color][color=BLUE]and[/color]
                           [color=RED]([/color][color=BLUE]vlax-property-available-p[/color] [color=RED]([/color][color=BLUE]setq[/color] obj [color=RED]([/color][color=BLUE]vlax-ename->vla-object[/color] ent[color=RED]))[/color] [color=DARKRED]'[/color]area[color=RED])[/color]
                           [color=RED]([/color][color=BLUE]not[/color] [color=RED]([/color][color=BLUE]vl-catch-all-error-p[/color] [color=RED]([/color][color=BLUE]vl-catch-all-apply[/color] [color=DARKRED]'[/color][color=BLUE]vla-get-area[/color] [color=RED]([/color][color=BLUE]list[/color] obj[color=RED]))))[/color]
                       [color=RED])[/color]
                       [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]setq[/color] pt [color=RED]([/color][color=BLUE]getpoint[/color] [color=#a52a2a]"\nSpecify Point for Field: "[/color][color=RED]))[/color]
                           [color=RED]([/color][color=BLUE]vla-addtext[/color]
                               [color=RED]([/color][color=BLUE]vlax-get-property[/color] [color=RED]([/color][color=BLUE]setq[/color] doc [color=RED]([/color][color=BLUE]vla-get-activedocument[/color] [color=RED]([/color][color=BLUE]vlax-get-acad-object[/color][color=RED])))[/color]
                                   [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]=[/color] [color=#009900]1[/color] [color=RED]([/color][color=BLUE]getvar[/color] [color=DARKRED]'[/color]CVPORT[color=RED]))[/color]
                                       [color=DARKRED]'[/color]Paperspace
                                       [color=DARKRED]'[/color]Modelspace
                                   [color=RED])[/color]
                               [color=RED])[/color]
                               [color=RED]([/color][color=BLUE]strcat[/color]
                                   [color=#a52a2a]"%<\\AcObjProp Object(%<\\_ObjId "[/color]
                                   [color=RED]([/color][color=BLUE]if[/color]
                                       [color=RED]([/color][color=BLUE]and[/color]
                                           [color=RED]([/color][color=BLUE]vl-string-search[/color] [color=#a52a2a]"64"[/color] [color=RED]([/color][color=BLUE]getenv[/color] [color=#a52a2a]"PROCESSOR_ARCHITECTURE"[/color][color=RED]))[/color]
                                           [color=RED]([/color][color=BLUE]vlax-method-applicable-p[/color] [color=RED]([/color][color=BLUE]vla-get-utility[/color] doc[color=RED])[/color] [color=DARKRED]'[/color]getobjectidstring[color=RED])[/color]
                                       [color=RED])[/color]
                                       [color=RED]([/color][color=BLUE]vla-getobjectidstring[/color] [color=RED]([/color][color=BLUE]vla-get-utility[/color] doc[color=RED])[/color] obj [color=BLUE]:vlax-false[/color][color=RED])[/color]
                                       [color=RED]([/color][color=BLUE]itoa[/color] [color=RED]([/color][color=BLUE]vla-get-objectid[/color] obj[color=RED]))[/color]
                                   [color=RED])[/color]
                                   [color=#a52a2a]">%).Area \\f \""[/color] format [color=#a52a2a]"\">%"[/color]
                               [color=RED])[/color]
                               [color=RED]([/color][color=BLUE]vlax-3D-point[/color] [color=RED]([/color][color=BLUE]trans[/color] pt [color=#009900]1[/color] [color=#009900]0[/color][color=RED]))[/color]
                               [color=RED]([/color][color=BLUE]getvar[/color] [color=DARKRED]'[/color]TEXTSIZE[color=RED])[/color]
                           [color=RED])[/color]
                       [color=RED])[/color]
                       [color=RED]([/color][color=BLUE]princ[/color] [color=#a52a2a]"\nInvalid Object."[/color][color=RED])[/color]
                   [color=RED])[/color]
               [color=RED])[/color]
           [color=RED])[/color]
       [color=RED])[/color]
   [color=RED])[/color]
   [color=RED]([/color][color=BLUE]princ[/color][color=RED])[/color]
[color=RED])[/color]

Also, you may want to take a look at my program here. To include the Conversion Factor, change the 'Field Formatting' line at the top of the code to:

 

[color=#a52a2a]"%lu2%ct8[0.0001]"[/color]

Posted

@lee mac

 

thank you very much for that code. its even better than what i wanted in the first place.

 

and yes, you are right about bad explanation of problem, but i was afraid that if i write too many words in post, people wont read it.

Posted
thank you very much for that code. its even better than what i wanted in the first place.

 

You're welcome, happy to help.

 

and yes, you are right about bad explanation of problem, but i was afraid that if i write too many words in post, people wont read it.

 

I understand where you are coming from, but consider the opposite too - if too little information is given, people may not want to spend time trying to ascertain what you are actually looking for.

 

On this theme, this is a very interesting read.

 

Lee

Posted

can i ask you to write me similar code for length, just to scale it 0.01 times?

Posted

The modifications aren't too many:

 

(defun c:test ( / doc ent format obj pt ) (vl-load-com)

   (setq format "%lu2%ct8[[color=red]0.01[/color]]") ;; Field Formatting Code

   (while
       (progn (setvar 'ERRNO 0) (setq ent (car (entsel)))
           (cond
               (   (= 7 (getvar 'ERRNO))
                   (princ "\nMissed, try again.")
               )
               (   (eq 'ENAME (type ent))
                   (if
                       (and
                           (vlax-property-available-p (setq obj (vlax-ename->vla-object ent)) '[color=red]length[/color])
                           (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-[color=red]length[/color] (list obj))))
                       )
                       (if (setq pt (getpoint "\nSpecify Point for Field: "))
                           (vla-addtext
                               (vlax-get-property (setq doc (vla-get-activedocument (vlax-get-acad-object)))
                                   (if (= 1 (getvar 'CVPORT))
                                       'Paperspace
                                       'Modelspace
                                   )
                               )
                               (strcat
                                   "%<\\AcObjProp Object(%<\\_ObjId "
                                   (if
                                       (and
                                           (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
                                           (vlax-method-applicable-p (vla-get-utility doc) 'getobjectidstring)
                                       )
                                       (vla-getobjectidstring (vla-get-utility doc) obj :vlax-false)
                                       (itoa (vla-get-objectid obj))
                                   )
                                   ">%).[color=red]Length[/color] \\f \"" format "\">%"
                               )
                               (vlax-3D-point (trans pt 1 0))
                               (getvar 'TEXTSIZE)
                           )
                       )
                       (princ "\nInvalid Object.")
                   )
               )
           )
       )
   )
   (princ)
)

 

Perhaps the better approach would be to create a subfunction requiring the property and field formatting as arguments, then call the subfunction from the two programs:

 

(defun c:afield nil (CreateField "Area" "%lu2%ct8[0.0001]"))
(defun c:lfield nil (CreateField "Length" "%lu2%ct8[0.01]"))

(defun CreateField ( prop format / doc ent obj pt spc )
   (setq doc (vla-get-activedocument (vlax-get-acad-object))
         spc (vlax-get-property doc (if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace))
   )
   (while
       (progn (setvar 'ERRNO 0) (setq ent (car (entsel)))
           (cond
               (   (= 7 (getvar 'ERRNO))
                   (princ "\nMissed, try again.")
               )
               (   (eq 'ENAME (type ent))
                   (if
                       (and
                           (vlax-property-available-p (setq obj (vlax-ename->vla-object ent)) prop)
                           (not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-get-property (list obj prop))))
                       )
                       (if (setq pt (getpoint "\nSpecify Point for Field: "))
                           (vla-addtext spc
                               (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                                   (if
                                       (and
                                           (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
                                           (vlax-method-applicable-p (vla-get-utility doc) 'getobjectidstring)
                                       )
                                       (vla-getobjectidstring (vla-get-utility doc) obj :vlax-false)
                                       (itoa (vla-get-objectid obj))
                                   )
                                   ">%)." prop " \\f \"" format "\">%"
                               )
                               (vlax-3D-point (trans pt 1 0)) (getvar 'TEXTSIZE)
                           )
                       )
                       (princ "\nInvalid Object.")
                   )
               )
           )
       )
   )
   (princ)
)
(vl-load-com) (princ)

 

Here you would type 'afield' for the Area Field, and 'lfield' for the Length Field. Notice how I have supplied the arguments to the subfunction from these commands.

Posted

yea, that last code is perfect. it will help me a lot in next project. thank you again.

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