Jump to content

Subtract Stationing and Insert Value into Block


Ohnoto

Recommended Posts

I am trying to modify coding to insert a box between two matchlines. However, our matchlines are usually placed at different angles and locations that doing a perfect distance between wouldn't give the correct value, so I am wanting to subtract the values from each stationing.

 

This would then insert our placement box between each matchline and put in the distance value of the difference between the two.

 

(defun c:cobi  (/ AddOffset cobc SelSet StrValidate AttVal StaList p1 p2 dblk cobscale)
(vl-load-com)
(if (null extekScale) (setq extekScale 30))
(defun AddOffset  (lst)  
(list (+ (car lst) cobffsetx) (- (cadr lst) cobffsety) 0.0))

(setq cobc (vla-get-activedocument (vlax-get-acad-object)))
(if (ssget ":L" '((0 . "INSERT")(2 . "`*U*,VIEWPORTLINE")))
(cond (
(vlax-for
      Sta
         (setq SelSet (vla-get-activeselectionset cobc))
     (if (and (equal (vla-get-effectivename sta) "VIEWPORTLINE")
              (/= (setq StrValidate
                             (vla-get-textstring
                                   (car (setq AttVal
                                                   (vlax-invoke
                                                         Sta
                                                         'GetAttributes)))))
                  ""))
           (setq StaList
                      (cons
                            (list StrValidate (nth 26 AttVal))
                            StaList))
           )
     )

 (setq cobscale (getint (strcat "\n Block Scale factor [30/50/100] <" (itoa (setq cobscale extekScale)) "> : ")))
 (if (null cobscale) (setq cobscale extekScale))
           (while (and (/= cobscale 30) (/= cobscale 50) (/= cobscale 100))
               (setq cobscale (getint (strcat "\n Block Scale factor [30/50/100] <" (itoa (setq cobscale extekScale)) "> : ")))
               (if (null cobscale) (setq cobscale extekScale))
               )
           (setq extekScale cobscale)
           (Cond
               ((= extekScale 30) (setq cobscale "1.0000") (setq blockname "call out box 1 (30)") (setq cobffsetx 11.25) (setq cobffsety 11.0135))
               ((= extekScale 50) (setq cobscale "1.6667") (setq blockname "call out box 1 (50)") (setq cobffsetx 18.75) (setq cobffsety 18.3559))
               ((= extekScale 100) (setq cobscale "3.3333") (setq blockname "call out box 1 (100)") (setq cobffsetx 37.5) (setq cobffsety 36.7117))
               ('T ((setq extekScale 1.0000) (princ "\n  !!! SCALE ERROR !!!\n"))))
      
(setq StaList
          (vl-sort
                StaList
                (function
                      (lambda (p1 p2)
                            (<
                                  (distof (vl-string-subst
                                                "."
                                                "+"
                                                (car p1))
                                          2)
                                  (distof (vl-string-subst
                                                "."
                                                "+"
                                                (car p2))
                                          2))))))
(while (and (setq p1 (car StaList))
          (setq p2 (cadr Stalist)))
     (setq p1     (AddOffset (vlax-get (cadr p1) 'insertionpoint))
           p2     (AddOffset (vlax-get (cadr p2) 'insertionpoint))
           cobdist (distance p1 p2)
           cobdist (rtos cobdist 2 0)
           cobmid  (mapcar (function (lambda (a b) (/ (+ a b) 2.)))
                           p1
                           p2)
           cobang  (angle p1 p2))
    (setq dblk (vlax-invoke
                     (vla-get-modelspace cobc)
                     'insertblock
                     cobmid
                     blockname
                     cobscale
                     cobscale
                     cobscale
                     cobang)
          )
    (vla-put-textstring
          (car (vlax-invoke dblk 'Getattributes))
          cobdist)
    (setq Stalist (cdr StaList))
     )
)
)
(vla-delete Selset)
)
(princ)                
)

Attached is the matchline and placement box.

 

My other question is how to determine the nth value. Since the code I am adjusting has nth 26, and that's where I am confused about and where I think where the first potential error lies. :? If I had a better understanding of the nth and what determines the value, I may not even need to post this...

Viewport.dwg

Edited by Ohnoto
Link to comment
Share on other sites

Forgive me if I've asked this before, but given the use of Stations, etc., why are you (your company) using Vanilla AutoCAD instead of Civil 3D?

 

Just a couple of suggestions:

 

The vlax-for statement returns nil, and is at the top of your cond statement, thereby exlcuding the rest of the code, jumping straight to (vla-delete Selset).

 

Also, cobVerNum = nil, hence:

 

_$ (princ (strcat "\n -------- Call Out Box Insert - Version " cobVerNum " --------"))
; error: bad argument type: stringp nil
_$ 

Edited by BlackBox
Typo
Link to comment
Share on other sites

That "cobvernum" I forgot to edit out of the original code. The variable for that is specified before the defun.

 

We aren't using Civil 3D because all that our owner has ever gotten is Vanilla AutoCAD. We do have Civil 3D on one computer, but he was lucky to get it because he does surveying. Our owner just isn't wanting to get Civil 3D for everyone.

Link to comment
Share on other sites

That "cobvernum" I forgot to edit out of the original code. The variable for that is specified before the defun.

 

We aren't using Civil 3D because all that our owner has ever gotten is Vanilla AutoCAD. We do have Civil 3D on one computer, but he was lucky to get it because he does surveying. Our owner just isn't wanting to get Civil 3D for everyone.

 

That's unfortunate.

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