Author Topic: Getting from a block ...  (Read 6244 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Getting from a block ...
« Reply #15 on: October 20, 2006, 02:58:08 PM »
There can be a problem with a routine based on what I gave you.  If the center point of the circle isn't the same as the insertion point of the block, then you will have to find it.  If the block is scaled, you will have to multiply the scale amount and the radius.  If the block is mirrored, or rotated in a weird way, then getting the correct location of the circle may not be as easy as one would want.

With that said, there is an easy 'fudge' fix.  You can use the ActiveX controls to explode the block, which will make a list of all the objects of the block, and will leave the block as a block within the drawing.  Then you can step through the list, and get the circle object, and all the information, center point and radius, will be correct.  Then you will just delete the objects from the drawing.

Let me know which way you want to go.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Getting from a block ...
« Reply #16 on: October 20, 2006, 03:58:21 PM »
Quote
... getting the correct location of the circle may not be as easy as one would want.

Ohh Man !!!   :-o  This is just gett'n worse and worse.  :-D

Ok, so, ...  seriously now, ...  :x
Quote
You can use the ActiveX controls to explode the block, which will make a list of all the objects of the block, and will leave the block as a block within the drawing.  Then you can step through the list, and get the circle object, and all the information, center point and radius, will be correct.  Then you will just delete the objects from the drawing.

Let me know which way you want to go.

Well, I'm a think'n we'll pass the ActiveX controls for the moment.  The insertion point is the center of the circle and the block is made at the end of its' design so it will be (9 times out of 10) a 1 to 1 scale.  The user would have to manually scale the thing which wouldn't make much sense.

Am I correct in my assumption;
Quote
I've run your routine and it worked well.  But when I try to assoc 40 for the circle, I get (40 . 0.0)
So with this info, I'm assuming I'll have to get to 'could-er, caid-er, cadd-er' to get the (40 . 0.375) radius I need ?.?

If not, then we need to keep digging.  If so, then I might have a way through this.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Getting from a block ...
« Reply #17 on: October 20, 2006, 04:09:28 PM »
Okay so if the insertion point is the same as the center of the circle, and the block will not be scaled (I don't like to make assumptions like this), you could do this.  Lunch time for me now.
Code: [Select]
(progn
(setq Sel (entsel "\n Select block: "))
(setq EntData (entget (car Sel)))
(setq BlkName (cdr (assoc 2 EntData)))
(setq BlkDefEnt (tblobjname "block" BlkName))
(setq tempEnt BlkDefEnt)
(while (setq tempEnt (entnext tempEnt))
 (setq tempEntData (entget tempEnt))
 (if (= (cdr (assoc 0 tempEntData)) "CIRCLE")
  (progn
   (prompt (strcat "\n Insertion point of block: " (vl-princ-to-string (cdr (assoc 10 EntData)))))
   (prompt (strcat "\n Circle radius is: " (rtos (cdr (assoc 40 tempEntData)) 2 5)))
  )
 )
)
(princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

uncoolperson

  • Guest
Re: Getting from a block ...
« Reply #18 on: October 20, 2006, 04:13:04 PM »
could i get a copy of the block creation code?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Getting from a block ...
« Reply #19 on: October 20, 2006, 04:17:21 PM »
The center of the circle (assoc 10 EntData) is relative to the insertion point of the block, not the actual WCS point.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Getting from a block ...
« Reply #20 on: October 20, 2006, 05:39:57 PM »
Quote
(I don't like to make assumptions like this)
Sorry Tim.  Perhaps I am not understanding what all you are seeking.  I am just the opposite, I try to make all the assumptions I can so my code will catch every scenario possible.


Quote
could i get a copy of the block creation code?
Certainly.
Code: [Select]
...
  (setq bolt_size (getreal (strcat "\nEnter Bolt diameter <" (rtos defbolt_size) ">: ")))
  (or bolt_size (setq bolt_size defbolt_size))
  (setq ipt (getvar "viewctr"))
;
  (setq rad1 (* 0.5 bolt_size))
  (setq pt1 (polar ipt (/ pi 2) (* 0.86603 bolt_size)))
  (setq pt2 (polar ipt (/ pi 2) rad1))
;
  (command ".-layer" "T" "0" "")
  (command ".-layer" "ON" "0" "")
  (setvar "clayer" "0")
;
  (command ".circle" ipt rad1)
  (setq ssel (ssget "l"))
  (command ".polygon" "6" ipt "c" pt1)
  (setq ssel (ssadd (entlast) ssel))
;
  (setq fname (getvar "dwgname"))
  (setq fnamel (strlen fname))
  (setq fname (substr fname 1 (- fnamel 4)))

  (command ".purge" "b" "" "n")
  (setq fn 0)
  (while (/= (tblsearch "block" (strcat "bolte" fname (itoa fn))) nil)
         (setq fn (+ fn 1))
  )
  (setq blnm (strcat "bolte" fname (itoa fn)))
  (command ".block" blnm ipt ssel "")
;
  (if (= (tblsearch "layer" "S-Object") nil)
    (command ".-layer" "n" "S-Object" "c" "3" "S-Object" "")
  )
  (command ".-layer" "T" "S-Object" "")
  (command ".-layer" "ON" "S-Object" "")
  (setvar "clayer" "S-Object")
;
  (setvar "osmode" 182)
  (setq inspt (getpoint (strcat "\nWhere do you want your "(rtos bolt_size)" bolt put?: ")))
  (command ".insert" blnm inspt "" "" "")
...

In fact, Here's most of the code.  This will show you how the bolt is made, how the block is made, and the placement of the block.
All I cut out is the misc. (setvar ... ) and (error ... ) crap.   stuff.

CAB, you are correct, the insertion point of the block is relative to the center of the circle.

Tim, give me a few minutes to look at your code, I've gotta put out another fire.

-- Funny, I don't remember learning the in's and out's of a fireman's job when I was in school learning to draw a straight line.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

uncoolperson

  • Guest
Re: Getting from a block ...
« Reply #21 on: October 20, 2006, 06:10:49 PM »
Code: [Select]
(setq coords (acet-geom-ss-extents (ssadd (car (entsel))) t))
(/ (/ (abs (- (cadr (car coords)) (cadr (cadr coords)))) 0.86603) 2)

should work... it may not be the 'right' way... but it spits out a number that so far looks right

Hangman

  • Swamp Rat
  • Posts: 566
Re: Getting from a block ...
« Reply #22 on: October 20, 2006, 06:49:37 PM »
Tim,
Nicely done.  I now have the radius set to a variable I can use & the insertion point.  Thank you !!

Now, ...  Uuuummmm,  Can you tell me what it's doing ??   :|

I don't understand why I was having such a difficult time with it.
Quote
I've run your routine and it worked well.  But when I try to assoc 40 for the circle, I get (40 . 0.0)
So with this info, I'm assuming I'll have to get to 'could-er, caid-er, cadd-er' to get the (40 . 0.375) radius I need ?.?

I put in the following and had errors:
Code: [Select]
... (if (= (cdr (assoc 0 tempEntData)) "CIRCLE")
          (progn
            (setq inspt (cdr (assoc 10 EntData)));;; I would usually get (10 . 0.0)
            (setq radi (cdr (assoc 40 tempEntData)));;; I would usually get (0.0) if I didn't get an entityp error.
          )
        )
...
 I tried this as well ... (setq radi (assoc 40 tempEntData)) ... ;;; And I would get (40 . 0.0)

I had gone through this several different ways and kept getting errors.  That's why I assumed I'd have to play with the 'car' sequences to extract the radius & insertion point.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hangman

  • Swamp Rat
  • Posts: 566
Re: Getting from a block ...
« Reply #23 on: October 20, 2006, 06:54:27 PM »
hey uncool,

You a ... lost me.  What ummm, ... should I do with this.
Code: [Select]
(setq coords (acet-geom-ss-extents (ssadd (car (entsel))) t))
(/ (/ (abs (- (cadr (car coords)) (cadr (cadr coords)))) 0.86603) 2)

 ???  I don't have a clue   :?  sorry.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Getting from a block ...
« Reply #24 on: October 20, 2006, 07:05:50 PM »
Tim,
Nicely done.  I now have the radius set to a variable I can use & the insertion point.  Thank you !!

Now, ...  Uuuummmm,  Can you tell me what it's doing ??   :|

I don't understand why I was having such a difficult time with it.
Sure.
Code: [Select]
(progn
(setq Sel (entsel "\n Select block: "))
; Selects the entity
(setq EntData (entget (car Sel)))
; Gets the dxf code list of said entity
(setq BlkName (cdr (assoc 2 EntData)))
; Gets the block name for said code list
(setq BlkDefEnt (tblobjname "block" BlkName))
; Gets the entity name of the blocks definition, in the block table
(setq tempEnt BlkDefEnt)
; Sets a temp variable to the blocks entity's name, see why next
(while (setq tempEnt (entnext tempEnt))
; Here we are going to step through the block with 'entnext'
; this will run until there are no more enitities (blocks definition)
 (setq tempEntData (entget tempEnt))
; Gets the dxf code for the entities of the blocks definition
 (if (= (cdr (assoc 0 tempEntData)) "CIRCLE")
; Sees if the entity is a 'circle'
  (progn
   (setq inspt (cdr (assoc 10 EntData)));;; I would usually get (10 . 0.0)
; Since it is a circle, and the block has the same insertion point of the block
; we grab the insertion point of the block 'EntData' NOT the center point of
; the circle, as that would be '(0.0 0.0 0.0)', as it is the origin point of the block
   (setq radi (cdr (assoc 40 tempEntData)));;; I would usually get (0.0) if I didn't get an entityp error.
; Here is where we grab the radius value of the circle 'tempEntData'
  )
 )
)
(princ)
)

Hope that makes it clearer.  When you want to grab the value of the dxf code you must use 'cdr' in association with 'assoc' and the number of the dxf code you want.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

uncoolperson

  • Guest
Re: Getting from a block ...
« Reply #25 on: October 20, 2006, 07:13:15 PM »
all that does is takes the block as a whole uses acet-geom-ss-extents to get the overall height, plugs in some math (that i put together badly)...

it just does the math backwards to get you the number the user entered in when building the block

gets the extents and sets that to coords
Code: [Select]
(setq coords (acet-geom-ss-extents (ssadd (car (entsel))) t))
returns the size (based off math in your building routine, and some bad stuff by me)
Code: [Select]
(/ (/ (abs (- (cadr (car coords)) (cadr (cadr coords)))) 0.86603) 2)
you could also use the coords list to get the center point of the block  with some averaging.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Getting from a block ...
« Reply #26 on: October 20, 2006, 07:23:30 PM »
Ahh, very understandable now uncool, ... Should be Too-Cool, :D
That makes sense & I like the reverse approach your making.  I'm going to keep this in mind (well, in my notes anyway).
Thank you.

And Thanks again Tim.  I really appreciate your help.  And everyone else who has contributed to this string.

I think I've found another area I've been misunderstanding as well.
the line
Code: [Select]
(if (= (cdr (assoc 0 tempEntData)) "CIRCLE")
associates everything.  And IF the tempEntData is not a "CIRCLE", then it loops until it is, right ?.

I know, I'm a little slow.  I like to break things down to a word for word research, I tend to understand it better that way.

Thanks again everyone.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Getting from a block ...
« Reply #27 on: October 20, 2006, 07:34:50 PM »
And Thanks again Tim.  I really appreciate your help.  And everyone else who has contributed to this string.

I think I've found another area I've been misunderstanding as well.
the line
Code: [Select]
(if (= (cdr (assoc 0 tempEntData)) "CIRCLE")
associates everything.  And IF the tempEntData is not a "CIRCLE", then it loops until it is, right ?.

I know, I'm a little slow.  I like to break things down to a word for word research, I tend to understand it better that way.

Thanks again everyone.
You're welcome.  And yes, that is what the 'if' statement is doing.  If it's not a circle, who cares because all we care about (with this code) is a circle.  dxf code 0 = Entity name (type)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.