Count & dimension polylines

Count & dimension polylines

Anonymous
Not applicable
8,443 Views
16 Replies
Message 1 of 17

Count & dimension polylines

Anonymous
Not applicable

Hi,

 

I'm not sure how to write lisp coding correctly. I'm looking for a quicker way to annotate drawings.

Currently I have to add dimensions to polylines and place a text number to each one effectively counting them.

I have found that I can add the text then use TCOUNT to replace the text by selection order.

 

Capture.JPG

 

Is it possible to make a lisp that can add a text near the selected polylines and add a dimension?

0 Likes
Accepted solutions (1)
8,444 Views
16 Replies
Replies (16)
Message 2 of 17

Kent1Cooper
Consultant
Consultant

Welcome to these Forums!

 

For the dimensioning part, there are several routines out there that will do that, such as this one [that's mine, and I remembered what it was called, making it easy to find with a Search, but there are others].  It places all Dimensions on the same side of the Polyline, and would therefore not do quite what's in your image, but is there some criterion by which you would want them positioned that can be defined in such a way that a routine could figure it out?  The alternative is for you to have to chase it around and give it a side for the dimension on each segment.

 

For the numbering part, I guess it wouldn't be too hard to add that if they can be [for example] on the same side as the dimension, and middle-justified with insertion points at some fixed multiple of the distance from the segment to the dimension line.  Again, if it can't be regular like that in some definable way, you'll have to specify yourself for each one.

 

Some questions:  I am imagining that the image shows one three-segment Polyline, but certain things in your wording make me wonder whether it's three separate one-segment Polylines.  If the former, are you talking about numbering the segments along each Polyline, and starting the numbering at 1 again for each, or should the numbering on the next Polyline start at 4?  [Or would you not need to do more than one at a time?]  If the latter, how would a routine decide the order?  Would you be willing to pick them one at a time in the order you want them numbered?  [And is there any reason they're not just Lines?]

Kent Cooper, AIA
0 Likes
Message 3 of 17

Anonymous
Not applicable

Thank you 🙂

 

The image is a basic version of what I'm working with but it helps to explain what I'm trying to achieve. The dimension doesn't matter so much as which side as I'll still have to modify it's location for clarity.

 

The numbering. For the most part it's usually on the same side as the dimension about centre of the line. The polylines would all be separate, so I'd be counting the amount of polylines. I've selected polylines because there are other objects are just basic lines so it'd make it possible to filter out the objects that need the dimensions and numbering. Picking the lines one at a time to define the order would be perfect.

 

The end result is a drawing that has a number and dimension for each piece which it then added to a table. Currently we're just manually editing the table as I can't see any other way to generate this info. I've played around with ExtractData, but it only gives me the length and no sequence number. E.g.

list.JPG

 

I tried out your lisp but couldn't get it to work beyond selecting the polylines... not sure what I did wrong there.

If I can figure out just how to add the first two items then this will save me hours of work.

 

- Chris

0 Likes
Message 4 of 17

Anonymous
Not applicable

Hi,

 

i found this lisp maybe you need.

 

(defun c:test(/ plSet pLlst vLst oldOsn cAng cDis cPt cT)

(princ "\n<<< Select LwPolyline for dimensioning >>> ")
(if(setq plSet(ssget '((0 . "LWPOLYLINE"))))
(progn
(setq pLlst(vl-remove-if 'listp
(mapcar 'cadr(ssnamex plSet))))
(setvar "OSMODE" 0)(setvar "CMDECHO" 0)
(foreach pl pLlst
(setq vLst(mapcar 'cdr
(vl-remove-if-not
'(lambda(x)(= 10(car x)))(entget pl)))
oldOsn(getvar "OSMODE")
); end setq
(while(< 1(length vLst))
(setq cAng(angle(car vLst)(cadr vLst))
cDis(/(distance(car vLst)(cadr vLst))2)
cPt(polar(polar(car vLst)cAng cDis)
(+ cAng(/ pi 2))(* 2(getvar "DIMTXT")))
cT (polar(polar(car vLst)cAng cDis)
(+ cAng(/ pi 2))(* 4(getvar "DIMTXT")))
); end setq
(command "_.dimaligned"(car vLst)(cadr vLst) cPt)
(command "text" cT "" "" (rtos (1- (length vLst)) 2 0) "")
(setq vLst(cdr vLst))
); end while
); end foreach
(setvar "OSMODE" oldOsn)(setvar "CMDECHO" 1)
); end progn
); end if
(princ)
); end of c:pdim

0 Likes
Message 5 of 17

ВeekeeCZ
Consultant
Consultant

Just a simple idea how to add a number to dimensions to consider.

 

(defun c:DimAddNumber ( / i ss ed)
  
  (setq i -1)
  (if (setq ss (ssget '((0 . "DIMENSION"))))
    (repeat (sslength ss)
      (setq ed (entget (ssname ss (setq i (1+ i)))))
      (entmod (subst (cons 1 (strcat "<>\\X" (itoa (1+ i)) "."))
		     (assoc 1 ed)
		     ed))))
  (princ)
)

 

0 Likes
Message 6 of 17

3wood
Advisor
Advisor

You can also try ADDLINES which will add sequence number in front of length  of each polyline segment. Settings as shown below.

After that, you can use ExtractData from the texts to create the list.

 addlines.JPG

Message 7 of 17

Kent1Cooper
Consultant
Consultant

What would you think of the idea of incorporating the sequencing number into the Dimension text, something like this:

 

NumberedDimension.PNG

 

I don't think it would be hard to get a routine to add the sequencing number and [my arbitrary choice for differentiating it from the measurement -- do it however you choose] colon and space as a prefix to "<>" [representing the measured dimension] in a text override, as it draws the Dimension.

 

That way, you can get the information for both entries in the table for each piece from one object, rather than needing to keep track of two different objects and their relationship with each other.  The entity data for that dimension includes these entries:

 

(1 . "13: <>")  [the text override content]

and

(42 . 28.0)  [the actual measurement]

 

So you could get the sequencing number out of the entity data [let's say that's stored in an 'edata' variable], like this:

 

Command: (vl-string-right-trim ": <>" (cdr (assoc 1 edata)))
"13"

 

and the measurement as a text string like this:

Command: (rtos (cdr (assoc 42 edata)) 2 2)
"28.00"

 

[with whatever mode & precision arguments you prefer].

Kent Cooper, AIA
0 Likes
Message 8 of 17

Anonymous
Not applicable

Thanks for all the replies.

 

I tried Pony's lisp but it error after selecting the polylines.

 

BeezkeeCZ, this one worked so it could be a solution if nothing else works. Tried to use the EATTEXT on the dimensions after using this one but that didn't work.

 

3Wood, I had a play with the ADDLINES. Interesting but not quite what I'm looking for. I'll have a look at the other items on the web site.

 

Kent, I like the idea of a variable for the sequence number. It sounds a bit like something I would use in say Revit to add information that can be extracted later. We measure by the nearest whole millimetre e.g "151mm" and suppress the trailing zero's.

 

Thanks for the replies, I've found a few useful commands so far. 🙂

 

-Chris

0 Likes
Message 9 of 17

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... 

Kent, I like the idea of a variable for the sequence number. .... We measure by the nearest whole millimetre e.g "151mm" and suppress the trailing zero's.

....


A quickie modification, minimally tested, of the code in my earlier link is attached, to add sequencing numbers, resulting in this kind of thing:

 

DimPolySeq.PNG

 

See comments at the top of and within the .lsp file.

 

The mm suffix and round-to-nearest-whole-number dimension text are part of the Style definition.  In the arc-segment Dimensions, the whole number is forced only because I didn't change my Units settings to do that with all numbers, but if you can have them set that way, you can remove the mode and precision arguments from the (rtos) function.  [The mm suffix has to be forced onto it, and can't be part of the Style, because those are actually angular Dimensions.]

 

It currently requires you to recall the command for each, so you get to choose them in the order you prefer, but that also means you can choose the inside or outside one for each [I used DPI on the second-in-my-order lower left Polyline and DPO on the others].  It could be made to automatically recall, and just let you go around picking things, or even to let you select multiple Polylines at once if you don't care what order they're sequenced in.

 

It sequences the segments in each Polyline in the reverse order of that in which the Polyline was drawn, just because of the way the original code worked.  If it matters to do them in drawn order, that can be done.

Kent Cooper, AIA
Message 10 of 17

Anonymous
Not applicable

Kent, 

 

That Lisp worked really well being, able to just use the our current dimstyle is good. The angular dimension is a bonus, didn't think that was even possible. Smiley Happy

 

Selecting one by one is better as we can pick the sequence order. Is there a way to reset the order sequence once we finish dimensioning one part/product and start on a new part/product (within the same CAD file)?

 

Also the recall option would be useful. I am wondering if selecting multiple would work. The main reason for the sequence order is so we can relate each item type to a table.

list2.JPG

So if I just selected all the Cyan first. Run command for Yellow then Red. That should be ok.

I am also looking for a way to create the tables by selecting the polylines by type but it'd have to somehow have the right sequence number that relates to the dimension. I did find something that Lee Mac wrote for block counting. But I understand that what I'm trying to do might be too specific (even if I can create just one list and edit the numbers on the two).

 

Thanks for all your help so far.

-Chris

0 Likes
Message 11 of 17

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... Is there a way to reset the order sequence once we finish dimensioning one part/product and start on a new part/product (within the same CAD file)?

....


Either

(setq *DPseq nil)

or

(setq *DPseq 1)

would do that.

 

If you close a drawing, and later get back into it, the routine will also start over at 1, not a continuation of previous sequencing.  If you want to carry on in a new editing session from previous sequencing, do:

 

(setq *DPseq TheNextSequencingNumberYouWant)

 

I'll tweak it for automatic recall in a little while....

Kent Cooper, AIA
0 Likes
Message 12 of 17

Anonymous
Not applicable

Kent,

 

Things just got really busy so I wasn't able to get back to this one. With this info I was able to make a command to reset the counter after we've finished putting all the annotations on one detail and starting on the next. The guys just asked me is it possible to make the count red and above while leaving the rest color 7?

 

DimCountRed.JPG

 

Regards

Chris

0 Likes
Message 13 of 17

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... The guys just asked me is it possible to make the count red and above while leaving the rest color 7?


Why, yes -- try the attached.  [The rest will not be color 7 explicitly, but whatever colors are defined for the current Dimension Style.]

Kent Cooper, AIA
0 Likes
Message 14 of 17

Anonymous
Not applicable

Thanks. Works like a charm, that is perfect. Smiley Happy

0 Likes
Message 15 of 17

vporrash141089
Advocate
Advocate

Hello guys,

 

Great post! 

 

I was actually looking for something similar to this and it caught my attention how close it is to what I need, at some point on this thread it was discussed if the counter could be restarted, however I tried changing the counter so that it restarts to 1 every time the command is called and it would be even better if it gives you the option to either continue from last sequence point or restart. Question is how can I accomplish this? 🙂

 

Help is very much appreciated, I know it's not a very recent post but hopefully you can point me in the right direction.

 

- Victor

0 Likes
Message 16 of 17

Kent1Cooper
Consultant
Consultant

@vporrash141089 wrote:

.... the option to either continue from last sequence point or restart. ….


Replace this line:
….
  (setvar 'osmode 0)
  (if (not *DPseq) (setq *DPseq 1))
  (command
….

with this [minimally tested]:
…. (setvar 'osmode 0)
(if (or (not *DPseq) (progn (initget "Continue Reset") (= (getkword "\nContinue counter or Reset to 1 [Continue/Reset] <C>: ") "Reset") ); progn ); or (setq *DPseq 1); then ); if (command ….
Kent Cooper, AIA
Message 17 of 17

Anonymous
Not applicable

Is there a way to make the lisp work on all kinds of lines polylines arcs ... etc 

 

0 Likes