Jump to content

Recommended Posts

Posted

Hi,

I'm trying to find a lisp that gets the value of an attribute "COTA" tag of 2 blocks. And the distance between these blocks.

Then calculate the slope.

 

I have a similar code. But don't get attribute value.

(defun c:lp (/ ptoy dist altu perc)

(setq ptox (getpoint "\nClick first point: "))
(setq ptoy (getpoint "\nClick second point: "))

(setq dist (rtos (distance ptox ptoy) 2 2))

(setq altu (- (cadr ptoy) (cadr ptox)))

(setq perc (rtos (* (/ altu (atof dist)) 100) 2 2))

(princ (strcat "Distance = " dist " ; Perc = " perc "%"))

(princ)

);defun 

 

Please, see the File Attached.

It explain better my task.

 

Regards

e.g.dwg

Posted (edited)

(defun c:lp2 (/ _sel val b1 b2 f pt e_ diff distB)
(defun _addComma (str sp / a b m i lst)
   (if (numberp (read str))
     (progn
       (setq a   (vl-filename-base str)
             b   (substr str (1+ (strlen a)))
             m   (vl-string->list a)
             i   (length m)
             lst nil
       )
       (while (>= i 3)
         (setq lst (append (list sp
                                 (nth (- i 3) m)
                                 (nth (- i 2) m)
                                 (nth (1- i) m)
                           )
                           lst
                   )
               i   (- i 3)
         )
         lst
       )
       (strcat (substr str 1 i)
               (vl-list->string
                 (if (zerop i)
                   (cdr lst)
                   lst
                 )
               )
;;;    mod    
               (if b (vl-string-subst "," "." b) "")
;;    mod    
       )
     )
   )
 )      
(Defun _sel (msg / sel)
(princ (Strcat "\n<<Select " msg " Data>>"))
(While (null sel)
 (setq sel (ssget "_:S" '((0 . "INSERT")(2 . "SIMB_BOLINHA")))))
 (ssname sel 0))
(if
 (And (setq val nil
            b1  (_sel "First")
            b2  (_sel "Second")
      )
      (foreach e (list b1 b2)
        (setq f  nil
              pt (cdr (Assoc 10 (entget e)))
        )
        (if (and
              (while
                (and
                  (null f)
                  (eq (cdr (assoc 0 (setq e_ (entget (setq e (entnext e))))))
                      "ATTRIB"
                  )
                )
                 (if (eq "COTA" (strcase (cdr (assoc 2 e_))))
                   (Setq f (cdr (Assoc 1 e_)))
                 )
              )
              [b](progn
              (While (vl-string-position 46 f)
                    	(setq f (vl-string-subst  "" "." f)))
              (setq f (distof (vl-string-subst "." "," f)))
              (numberp f))
            )[/b]
          (setq val (cons (list f pt) val)
          )
        )
      )
      (vl-every '(lambda ( x ) x )(apply 'append val))
      (= (length val) 2)
 )
  (alert (Strcat "\nSlope: " (rtos (* (/ (setq diff (abs (- (Caar val) (caadr val))))
                             (setq distB (distance (cadar val) (cadadr val)))
                          )
                          100.00
                       )
                       2
                       2
                 )
                 "%" " \nDifference of Elevation: "[b] (_addComma (rtos diff 2 2) 46)[/b]
                     " \nDistance between BLocks: "[b] (_addComma (rtos distB 2 2) 46)[/b]
         )
  )(princ "\n<<<Missing Information, Check Attribute Value>>>:")
 )
  (princ)
)

 

Not use how accurate the result will be [As per your Formula]

Edited by pBe
Posted

I'm very impressed with the result.

It's just like I wanted to.

 

Many Thanks for the quickly reply and wonderful code.

 

:notworthy::notworthy::notworthy:

 

Best Regards

Posted
I'm very impressed with the result.

It's just like I wanted to.

Many Thanks for the quickly reply and wonderful code.

Best Regards

 

You are welcome, Glad it works for you.

 

Cheers

Posted

Hi,

I'm trying to add two more information inside the code, beside slope (%).

- unevenness (890,00 - 891,30) = 1.30

- distance (distance between two blocks)

 

In my drawing has about three kind of blocks, but the attribute is the same "COTA", and the lisp works just for SIMB_BOLINHA block.

Is it possible to add other names in the code, SIMB_PONTO, SIMB_CRUZETA?

 

Any help will be really wellcome, guys.

Thank in advance.

:oops:

Posted
Hi,

I'm trying to add two more information inside the code, beside slope (%).

- unevenness (890,00 - 891,30) = 1.30

- distance (distance between two blocks)

 

What is that? the difference of elevation? on what format?

 

In my drawing has about three kind of blocks, but the attribute is the same "COTA", and the lisp works just for SIMB_BOLINHA block.

Is it possible to add other names in the code, SIMB_PONTO, SIMB_CRUZETA?

 

 

(setq sel (ssget "_:S" '((0 . "INSERT")(2 . [b][color="blue"]"SIMB_BOLINHA,SIMB_PONTO,SIMB_CRUZETA"[/color][/b]))))

Posted

(setq sel (ssget "_:S" '((0 . "INSERT")(2 . "SIMB_BOLINHA[color="red"],[/color]SIMB_PONTO[color="red"],[/color]SIMB_CRUZETA"))))

 

Oh! I did this, but I forgot the comma. Thank you!

 

What is that? the difference of elevation? on what format?

Yes pBe. It's the difference of elevation.

The format is decimal (In Brazil decimal mark is comma.)

 

Regards

  • 2 weeks later...
Posted

Hi, pBe

I don't want to inconvenience you, I'd like to ask you just one more thing.

I need incorporate two more information in the code, beside slope (%).

 

-difference of elevation

-distance between blocks.

 

I would be very grateful if you could help me, I really need these informations in the code.

 

Thank in advance

Posted
Hi, pBe

I don't want to inconvenience you, I'd like to ask you just one more thing.

I need incorporate two more information in the code, beside slope (%).

 

I already did the modification at post # 6 a week ago Madruga_SP :)---> [Last edited by pBe; 27th May 2013 at 09:57 am.]

Posted

Hi pBe

I've noticed that you updated the code.

 

Now, I know because didn't work.

The value of attribute when is millesimal unit is separeted by period "."

e.g 1.200,00

 

Sorry bother you, could you help me for the last time?

 

I promess you.

:oops:

Posted

...

Now, I know because didn't work.

...

 

I promess you.

:oops:

 

Code updated

 

I wish you wouldn't :lol:

Posted
I promise you.

Oh Whoa...In fact english is really bad.

 

Code updated

 

I wish you wouldn't :lol:

 

I'm sure I won't my friend, because your code is just fantastic!

Worked like a charm!

 

I'm really satisfied with the goal, it was better than I thought.

Many thanks for the great help.

 

God Bless you!

:D

Posted

Many thanks for the great help.

 

You are welcome. Happy to help :)

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