X and Y coordinates

X and Y coordinates

Anonymous
Not applicable
703 Views
14 Replies
Message 1 of 15

X and Y coordinates

Anonymous
Not applicable
This should be fairly simple. I was just wondering what the command would be to obtain the x and y coordinates of a block reference.
Thanks
0 Likes
704 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable
well, with vb there are no "commands" as such. But to get the insertion
point of a block ref (assuming that's what you mean by x and y coordinates)
you use the InsertionPoint property.
oBlkRef.InsertionPoint
so then if what you mean is you want to create a "command" so to speak which
would report to you the insertion point of a selected block, then you'd
write a sub or function that would prompt you to select the block, then read
the InsertionPoint property, and finally report back to the user in some
way, with a dialog box or however, the result of it's inquiry. Then you'd
make some way, either a menu item or toolbar to call that vb sub and in that
way 'imitate' a "command" as such.

Is that what you were asking?

SomeGuy wrote in message
news:f0e4e08.-1@WebX.maYIadrTaRb...
> This should be fairly simple. I was just wondering what the command would
be to obtain the x and y coordinates of a block reference.
> Thanks
>
0 Likes
Message 3 of 15

Anonymous
Not applicable
Yep, sounds good. I'll try it.
Thanks.
0 Likes
Message 4 of 15

Anonymous
Not applicable
If I want to get the coordinates of my block reference, does "blockcoord = BlockRef.InsertionPoint" return the coordinates of where the block currently is, or where it was first inserted? I'm asking because when I have this command in my code, for many drawings it doesn't seem to return the current coordinates that the block is at. Could someone answer this question for me, and is there a better line of code to do what I'm asking?
Thanks
0 Likes
Message 5 of 15

Anonymous
Not applicable
It should be returning the current insertion
point.  Is it possible that you're using a user coordinate system? 
I'm not sure how VBA handles UCS, but that could explain seemingly erroneous
coordinates.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
If
I want to get the coordinates of my block reference, does "blockcoord =
BlockRef.InsertionPoint" return the coordinates of where the block currently
is, or where it was first inserted? I'm asking because when I have this
command in my code, for many drawings it doesn't seem to return the current
coordinates that the block is at. Could someone answer this question for me,
and is there a better line of code to do what I'm asking?

Thanks
0 Likes
Message 6 of 15

Anonymous
Not applicable
You should watch out as TomD is saying for the UCS thing, otherwise whatever you do will be affected, either from obtaining the wrong information from the block, or using it in such a way that it doesn't make sense for what you want to use it for.

As the result returned will be in WCS, try using the GETUCSMATRIX method in conjunction with the TRANSFORMBY method, to turn your result into your current UCS coordinates.
0 Likes
Message 7 of 15

Anonymous
Not applicable
I've looked, and the drawing doesn't use UCS - it's WCS. After lots of testing I think the problem might be that on the drawings that it's (edited) up my coordinates for, the block reference is on a different layer. Now, I've never really used AutoCAD before so this might just be totally wrong, but if this is the problem - how do I fix it? (do I change the layer of the block? change the active layer I'm on?)
Thanks in advance!
0 Likes
Message 8 of 15

Anonymous
Not applicable
I think you're going to have give us some more
info.  I'm 99% comfortable saying that there is no way the layer of the
block could have any effect on your insertion point.  (I don't want to say
100%, 'cause without details, you just never know.)
 
If possible, describe exactly the steps leading up
to and including the point at which you're extracting the coordinates. 
(I've been using Acad for over 10 years, but I just started dabbling with VBA
over the last few years.)

"SomeGuy" wrote in
message news:f0e4e08.5@WebX.maYIadrTaRb...I've
looked, and the drawing doesn't use UCS - it's WCS. After lots of testing I
think the problem might be that on the drawings that it's (edited) up my
coordinates for, the block reference is on a different layer. Now, I've never
really used AutoCAD before so this might just be totally wrong, but if this is
the problem - how do I fix it? (do I change the layer of the block? change the
active layer I'm on?) Thanks in advance!
0 Likes
Message 9 of 15

Anonymous
Not applicable
Ok, I'll post the code I use - I don't know if
it'll help or not.
 
        Set AcadApp =
CreateObject("Autocad.application")       
Dim Thisdrawing As AcadDocument       
FileNm = ActiveCell.Value        Set
Thisdrawing =
AcadApp.Documents.Open(FileNm)                       
AutoCAD.Application.Visible = True       
Dim Name As String        Dim BlockRef As
AcadBlockReference        Dim ss As
AcadSelectionSet       
        'Loop through the array NameList
to see if the drawing has a block by one of the following names - if so, select
it        NameList = Array("HZ-PIDSTP",
"HZ-NSTP", "HZ-BEAVER", "HZ-STAMP",
"HZ-SSTP")        Dim i As
Integer        i =
0        Set ss =
Thisdrawing.PickfirstSelectionSet       
ss.Clear        Do While ss.Count = 0 And
i <= 4        Name =
NameList(i)        Set ss =
Thisdrawing.PickfirstSelectionSet       
ss.Clear        Dim vt(0 To 1) As
Integer        vt(0) = 0: vt(1) =
2        ss.Select acSelectionSetAll, , ,
vt, Array("INSERT", Name)        If
ss.Count > 0
Then            Set
BlockRef = ss(0)        End
If        i = i +
1       
Loop                               
'Get the coordinates of
the block        Dim BlockCoords As
Variant        Dim NewCoords(0 To 2) As
Double        Dim RasterScale As
Double        BlockCoords =
BlockRef.InsertionPoint        
 
This is the code I use.  It works
perfectly fine when the block is on the layer "DIMENSION", but when it is on
another layer, it doesn't seem to work.  Maybe this is just coincidence or
something.  I just know that this is bugging me - it should work!  If
you have any suggestions, that would be great.
Thanks

"TomD"
wrote in message news:7373A983A9B1A874C37F800813B9FF8C@in.WebX.maYIadrTaRb...
I think you're going to have give us some more
info.  I'm 99% comfortable saying that there is no way the layer of the
block could have any effect on your insertion point.  (I don't want to
say 100%, 'cause without details, you just never know.)
 
If possible, describe exactly the steps leading
up to and including the point at which you're extracting the
coordinates.  (I've been using Acad for over 10 years, but I just started
dabbling with VBA over the last few years.)

"SomeGuy" wrote in
message news:f0e4e08.5@WebX.maYIadrTaRb...I've
looked, and the drawing doesn't use UCS - it's WCS. After lots of testing I
think the problem might be that on the drawings that it's (edited) up my
coordinates for, the block reference is on a different layer. Now, I've
never really used AutoCAD before so this might just be totally wrong, but if
this is the problem - how do I fix it? (do I change the layer of the block?
change the active layer I'm on?) Thanks in
advance!
0 Likes
Message 10 of 15

Anonymous
Not applicable
your routine only reads the insertion point for the first block in the sel
set
if there are more than one and you're looking for one of the others, that is
why you think it's giving you the wrong insertion point.
It's giving you the right insertion point but you're giving it the wrong
block to read the insertion point from?
maybe? dunno?

"kjohn" wrote in message
news:14DE8C8C4059B007B340C9920312C21F@in.WebX.maYIadrTaRb...
> Ok, I'll post the code I use - I don't know if it'll help or not.
>
> Set AcadApp = CreateObject("Autocad.application")
> Dim Thisdrawing As AcadDocument
> FileNm = ActiveCell.Value
> Set Thisdrawing = AcadApp.Documents.Open(FileNm)
>
> AutoCAD.Application.Visible = True
> Dim Name As String
> Dim BlockRef As AcadBlockReference
> Dim ss As AcadSelectionSet
>
> 'Loop through the array NameList to see if the drawing has a block
by one of the following names - if so, select it
> NameList = Array("HZ-PIDSTP", "HZ-NSTP", "HZ-BEAVER", "HZ-STAMP",
"HZ-SSTP")
> Dim i As Integer
> i = 0
> Set ss = Thisdrawing.PickfirstSelectionSet
> ss.Clear
> Do While ss.Count = 0 And i <= 4
> Name = NameList(i)
> Set ss = Thisdrawing.PickfirstSelectionSet
> ss.Clear
> Dim vt(0 To 1) As Integer
> vt(0) = 0: vt(1) = 2
> ss.Select acSelectionSetAll, , , vt, Array("INSERT", Name)
> If ss.Count > 0 Then
> Set BlockRef = ss(0)
> End If
> i = i + 1
> Loop
>
> 'Get the coordinates of the block
> Dim BlockCoords As Variant
> Dim NewCoords(0 To 2) As Double
> Dim RasterScale As Double
> BlockCoords = BlockRef.InsertionPoint
>
>
> This is the code I use. It works perfectly fine when the block is on the
layer "DIMENSION", but when it is on another layer, it doesn't seem to work.
Maybe this is just coincidence or something. I just know that this is
bugging me - it should work! If you have any suggestions, that would be
great.
> Thanks
> "TomD" wrote in message
news:7373A983A9B1A874C37F800813B9FF8C@in.WebX.maYIadrTaRb...
> I think you're going to have give us some more info. I'm 99%
comfortable saying that there is no way the layer of the block could have
any effect on your insertion point. (I don't want to say 100%, 'cause
without details, you just never know.)
>
> If possible, describe exactly the steps leading up to and including the
point at which you're extracting the coordinates. (I've been using Acad for
over 10 years, but I just started dabbling with VBA over the last few
years.)
> "SomeGuy" wrote in message
news:f0e4e08.5@WebX.maYIadrTaRb...
> I've looked, and the drawing doesn't use UCS - it's WCS. After lots of
testing I think the problem might be that on the drawings that it's (edited)
up my coordinates for, the block reference is on a different layer. Now,
I've never really used AutoCAD before so this might just be totally wrong,
but if this is the problem - how do I fix it? (do I change the layer of the
block? change the active layer I'm on?)
> Thanks in advance!
>
0 Likes
Message 11 of 15

Anonymous
Not applicable
Sorry, I should have mentioned that there will only be one block reference of the block I'm looking for in the drawing and the block name will only be one of those listed in the NameList array. For example, the block might be called "HZ-PIDSTP" - then there would only be one instance of it in the drawing, and there would be no instances of "HZ-BEAVER", "HZ-NSTP", etc.
0 Likes
Message 12 of 15

Anonymous
Not applicable
Ok, I finally found out the problem - thanks for trying to help.
0 Likes
Message 13 of 15

Anonymous
Not applicable
I'd appreciate knowing what it was, just in case I
come across the same situation.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Ok,
I finally found out the problem - thanks for trying to
help.
0 Likes
Message 14 of 15

Anonymous
Not applicable
Well, as I said - I haven't used autoCAD before, I'm just programming for it, so this may seem stupid to many of you veterans :).
I didn't realize the insertion point was the little blue box that comes up when you select the block. From my code, you can see that there were several different possible names for the block - I thought that they were all designed the same, but they weren't. Only one was different, "HZ-PIDSTP". It appeared the same as the others, but instead of having it's insertion point (little blue box) at the center of the logo, it was way off down and to the left of the block. So that's where my problem was - when I would select the block and expected to get coordinates for the center of the logo, I would get coordinates that were way off. This was bugging me because it worked for some and it didn't for others.
Well, that was it. *slaps self*
0 Likes
Message 15 of 15

Anonymous
Not applicable
Thanks for the update.  Even 'we veterans'
miss stuff like that, particularly when working with drawings that we didn't
create.  😮

 

Thanks again for posting the cause of your
troubles.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Well,
as I said - I haven't used autoCAD before, I'm just programming for it, so
this may seem stupid to many of you veterans :).
  I didn't
realize the insertion point was the little blue box that comes up when you
select the block. From my code, you can see that there were several different
possible names for the block - I thought that they were all designed the same,
but they weren't. Only one was different, "HZ-PIDSTP". It appeared the same as
the others, but instead of having it's insertion point (little blue box) at
the center of the logo, it was way off down and to the left of the block. So
that's where my problem was - when I would select the block and expected to
get coordinates for the center of the logo, I would get coordinates that were
way off. This was bugging me because it worked for some and it didn't for
others.
Well, that was it. *slaps self*
0 Likes