Jump to content

VisualLISP code regarding


BKRao

Recommended Posts

(defun c:stno ()
  (setq i (getint "\nEnter Start Plot No :"))
)
(defun c:pno ()
  (setq th 3)
  (if (= i nil)
    (setq i 1)
  )
  (setvar "osmode" 0)
  (setq pot (getpoint "\nPick a point for Plot Boundary and No :"))
  (setvar "osmode" 32)
  (setq pt1 (getpoint "\nPick 1st Corner Point for ins :"))
  (setq pt3 (getcorner pt1 "\nPick Other Corner Point for ins :"))
  (setvar "osmode" 0)
  (setq ins (polar pt1 (angle pt1 pt3) (/ (distance pt1 pt3) 2)))
  (if (/= pot nil)
    (command "-BOUNDARY" pot "") 
  )
  (command "text" "j" "mc" ins th "0" i)
  (setq i (+ i 1))
);defun

;;; Sir I am using above lisp. I want avoid
;;;1. Pick 1st Corner Point for ins
;;;2. Pick Other Corner Point for ins
;;;- kindly guide to me  Red colour rectangle is plot and yellow number is plot no. I want pick once only text always middle of plot only, if possible default no with thanksimage.png.97a3c9d53603f9609ad28a04ef858cd1.png

Text Mid.dwg

Link to comment
Share on other sites

If I had 20 boxes as a block with an attribute then could just plot all of them one after the other, if the rectang block has a scale as well then that that can be used as well.

 

Maratovich has some good plotting software for this type of question.

 

This has been asked before here at cadtutor.

 

Just my $0.05 I would look at layouts give up on model space title blocks. You could plot a specific layout by name using lisp automatically changing to it, like "1"

Edited by BIGAL
Link to comment
Share on other sites

Hi,

I need text not attributed block, before i was used attributed block

now i want middle of rectangle point

kindly help me

BKRao

Link to comment
Share on other sites

Yes sir, different size of rectangles draw before giving plot numbers.

I want text centre of rectangles

Edited by BKRao
Link to comment
Share on other sites

Try the attached. It incorporates the get start plot number into the lisp and will loop until a null selection is made at the "Select Plot Boundary " prompt.

 

The text is placed into the current active layer, but this is easy to change. It makes use of the GetBoundingBox method to retrieve the lower left and upper right extents, then calculates the mid point. This should work whatever the orientation of the rectangle.

 

plot-nos.lsp

Link to comment
Share on other sites

must admit I have a little difficulty to understand what it is exactly that OP wants , place a text in the center of a poly or find one...


; place a string in center of (all) poly's
(defun c:t1 ( / a sp ss i ts o l r pt to)
  (setq a (vla-get-activedocument (vlax-get-acad-object)) sp (vla-get-block (vla-get-activelayout a)))
  (prompt "\nSelect polylines to number :")
  (if (setq ss (ssget))
    (progn
      (setq i 0 ts (/ (getvar 'viewsize) 50) ss (vla-get-activeselectionset a))
      (vlax-for o ss
        (if (= (vlax-get-property o 'ObjectName) "AcDbPolyline")
          (progn
            (vla-getboundingbox o 'l 'r)
            (setq pt (mapcar '/ (mapcar '+ (vlax-safearray->list l) (vlax-safearray->list r)) '(2 2 2)))
            (setq to (vla-AddText sp (itoa (setq i (1+ i))) (vlax-3d-point pt) ts))
            (vla-put-Alignment to acAlignmentRight)
            (vla-put-textalignmentpoint to (vlax-3d-point pt))
            (vla-put-Alignment to acAlignmentMiddle)
          )
       )
      )
    )
  )
  (vla-Regen a acActiveViewport)
  (princ)
)

; finding a string in center of (all) poly's
(defun c:t2 ( / ss o l r sel lst)
  (if (setq ss (ssget "x" '((0 . "LWPOLYLINE"))))
    (vlax-for o (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
      (vla-getboundingbox o 'r 'l)
      (if (setq sel (ssget "w" (setq r (vlax-safearray->list r)) (setq l (vlax-safearray->list l)) '((0 . "TEXT"))))
        (setq lst (cons (cons (cdr (assoc 1 (entget (ssname sel 0)))) (list l r)) lst)))))
  (if (and (vl-consp lst) (setq plt (getstring "\nEnter plot number : ")) (assoc plt lst))
    (prompt (strcat "\nPlot number " plt " : " (vl-princ-to-string (cdr (assoc plt lst)))))
    (prompt "\nNo plotnumber found or selected")
  )
  (princ)
)

(vl-load-com)

  • Thanks 1
Link to comment
Share on other sites

Me to not sure what is going on, I think its a big sheet with little sheet blow ups.

 

My $0.05 use fence option for picking boxes so correct order maintained. 

 

Still dont understand why not a block so much easier to do plot range.

Link to comment
Share on other sites

8 hours ago, BIGAL said:

Me to not sure what is going on, I think its a big sheet with little sheet blow ups.

 

My $0.05 use fence option for picking boxes so correct order maintained. 

 

Still dont understand why not a block so much easier to do plot range.

 

I agree with you Bigal , why not use blocks or layouts. But maybe user has some historical baggage I dunno...

But if OP has to use polylines I would recommend putting them in a special layer so selecting them would be easier by including layer name in selection filter.

anyways , another code that also sorts the polylines (untested of course since we have no sample to test it on)


(defun c:t4 ( / a sp i ss to p)
  (setq a (vla-get-activedocument (vlax-get-acad-object)) sp (vla-get-block (vla-get-activelayout a)) i 0)
  (prompt "\nSelect polylines to number :")
  (if (setq ss (ssget ":L" '((0 . "LWPOLYLINE"))))
    (foreach p (vl-sort (mapcar '(lambda (x) (GetBcent x)) (setq ss (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
                       '(lambda (a b)(if (equal (cadr a) (cadr b) 1e-8) (< (car a) (car b)) (> (cadr a) (cadr b)))))
      (setq to (vla-AddText sp (itoa (setq i (1+ i))) (vlax-3d-point p) (/ (getvar 'viewsize) 50)))
      (vla-put-Alignment to acAlignmentRight)(vla-put-textalignmentpoint to (vlax-3d-point p))(vla-put-Alignment to acAlignmentMiddle)
    )
  )
  (vla-Regen a acActiveViewport)
  (princ)
)

; get boundingbox center
(defun GetBcent ( %e / ll ur)
  (if (= (type %e) 'ENAME)(setq %e (vlax-ename->vla-object %e)))
  (cond
    ; get the centerpoint from boundingbox
    ((and (vlax-method-applicable-p %e 'getboundingbox)
   (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list %e 'll 'ur)))))
     (mapcar (function (lambda (a b) (/ (+ a b) 2.)))(vlax-safearray->list ll)(vlax-safearray->list ur)))
    ; else get alignment or point
    ((and (vlax-method-applicable-p %e 'alignment)(= (vla-get-alignment %e) 1))
     (reverse (cdr (reverse (vlax-safearray->list (vlax-variant-value (vla-get-TextAlignmentPoint %e)))))))
    (t (reverse (cdr (reverse (vlax-safearray->list (vlax-variant-value (vla-get-InsertionPoint %e)))))))
  ) 
)

 

  • Thanks 1
Link to comment
Share on other sites

On 05/03/2019 at 22:03, dlanorh said:

Try the attached. It incorporates the get start plot number into the lisp and will loop until a null selection is made at the "Select Plot Boundary " prompt.

 

The text is placed into the current active layer, but this is easy to change. It makes use of the GetBoundingBox method to retrieve the lower left and upper right extents, then calculates the mid point. This should work whatever the orientation of the rectangle.

 

plot-nos.lsp 1.47 kB · 5 downloads

Thanking you 

plot-nos.lsp program is very good nearly to my requirement and 

I need small change in this program.

1. I want "pick" with in the plot boundary instead of "select plot boundary"

2. Usually plots are draw with "line", so again I want "Boundary" with in plot

3.Default number should be change to next plot number

requesting to update above program.

ones again thanking you

Link to comment
Share on other sites

Please advise if this is not correct.

 

1. You want to select inside the boundary. Does this mean you want the boundary created?  If so Layer/color/type for boundary.

2. You want a global counter for the plot number. Should this be for the session only or across multiple autocad sessions?

 

 

Link to comment
Share on other sites

If you just post a (sample) drawing with 'this is what I have' , 'this is what I want to select or here is where I want to click' and 'this is what I want to happen' your problem / challenge would probably already have been resolved. Now everybody is still guessing.

Link to comment
Share on other sites

3 hours ago, dlanorh said:

Please advise if this is not correct.

 

1. You want to select inside the boundary. Does this mean you want the boundary created?  If so Layer/color/type for boundary.

2. You want a global counter for the plot number. Should this be for the session only or across multiple autocad sessions?

 

 

 

3 hours ago, dlanorh said:

Please advise if this is not correct.

 

1. You want to select inside the boundary. Does this mean you want the boundary created?  If so Layer/color/type for boundary.

2. You want a global counter for the plot number. Should this be for the session only or across multiple autocad sessions?

 

 

1. Yes sir, I want select inside the boundary, respective layer.

2. I am providing "Layout" plots numbers, so always plot numbers sequence numbers only. (for example 1 to 100)

Please find the attachment of sample drawing "Text Mid.dwg" and run my "PlotNo.lsp"  you will better understating my requirement.

In my program I am "Pick one time for Plot Boundary" than "Pick two corners for text", Instead of I want select one time for Boundary and sequence Plot number.

BKRao

Text Mid.dwg PlotNo.lsp

Link to comment
Share on other sites

I cannot open your drawing. I need it in AutoCAD 2010 format.

 

I am still not sure of your requirements.

 

Do you need the boundary to be created?

 

Do you need the lisp to remember the last plot number across AUtoCAD sessions (A Dictionary entry in the drawing) or just when AutoCAD is running (a global variable) or both?

 

Link to comment
Share on other sites

@dlanorh : I think I understand what OP wants. He has 2 layers , the first has color cyan with name "& Plots" and this contains the original polylines that define the plot area's. The second layer , "_IndivSubPlot" which has color 180 (like blue). I think OP wants to be able to click inside one of the 'empty' cyan polylines in layer "& Plots" and the routine then is suppost to give the next plotnumber (I would suggest registry or sentenv or something) , place a new polyline in layer "_IndivSubPlot" with the next number. This way OP can see which 'grid area' has been processed / plotted. Have saved the dwg to 2010. I assume the cyan poly's won't be empty so maybe build assoc list with all cyan polly's so point selected can be tested for inside point. Think intersec with / raycasting would be slow if many objects inside the polly's. Should be doable...

Text Mid.dwg

Link to comment
Share on other sites

2 hours ago, rlx said:

@dlanorh : I think I understand what OP wants. He has 2 layers , the first has color cyan with name "& Plots" and this contains the original polylines that define the plot area's. The second layer , "_IndivSubPlot" which has color 180 (like blue). I think OP wants to be able to click inside one of the 'empty' cyan polylines in layer "& Plots" and the routine then is suppost to give the next plotnumber (I would suggest registry or sentenv or something) , place a new polyline in layer "_IndivSubPlot" with the next number. This way OP can see which 'grid area' has been processed / plotted. Have saved the dwg to 2010. I assume the cyan poly's won't be empty so maybe build assoc list with all cyan polly's so point selected can be tested for inside point. Think intersec with / raycasting would be slow if many objects inside the polly's. Should be doable..

 

Thanks rlx. :beer:

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