Insertion point not at 0,0

Insertion point not at 0,0

Anonymous
Not applicable
501 Views
10 Replies
Message 1 of 11

Insertion point not at 0,0

Anonymous
Not applicable
I wrote the following code to update the blocks in multiple drawings from a template drawing:


Option Explicit
Option Compare Text

Public Sub Update()
Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim objFile As Scripting.File
Dim objBlockRef As AcadBlockReference
Dim dblInsPt(2) As Double
Dim varInsPt As Variant
dblInsPt(0) = 0
dblInsPt(1) = 0
dblInsPt(2) = 0
varInsPt = dblInsPt
Set objFSO = New Scripting.FileSystemObject
Set objFolder = objFSO.GetFolder("Z:\Products\EXTERNAL\Limestone Coast Tourism\Atlas\BatchUpdate")
For Each objFile In objFolder.Files
If objFile.Name Like "*.dwg" = True Then
ThisDrawing.New "Z:\Products\EXTERNAL\Limestone Coast Tourism\Atlas\Page-Blocks.dwt"
Set objBlockRef = ThisDrawing.ModelSpace.InsertBlock(varInsPt, objFile.Path, 1, 1, 1, 0)
objBlockRef.Explode
objBlockRef.Delete
Application.ZoomExtents
ThisDrawing.PurgeAll
ThisDrawing.SaveAs objFile.Path, ac2004_dwg
End If
Next objFile
ThisDrawing.New "Z:\RAA_UTIL04\Batch.dwt"
End Sub

The program seemed to work OK but if you then try and insert the updated drawing into a new drawing manually or programatically the insertion point is not from 0,0 as the original drawing was.



The program basically works by opening a template, inserting the drawing to be updated, exploding the resulting block and then saving as the drawing that was inserted. It should be a simple, straightforward process but I can't figure out why it is doing what it is.



Regards - Nathan
0 Likes
502 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
You should check that the prototype drawing has
it's base point (origin) in origo and that UCS is WCS.

 

A few other comments:

 

1:

You don't really need the dblInsPt variable. It's
enough to dim a variant and then redim it:

Dim varInsPt as Variant

Redim varInsPnt(2) as Double

 

The three cells in this array will have default
values 0.0

 

2:

At the end of your sub you should set all objects
to nothing.

 

3:

In addition to deleting the block reference, you
should delete the block definition. Get the block definition before you delete
the block reference, delete it after you delete the block
reference:

Dim objBlock As AcadBlock

...

Set objBlock =
ThisDrawing.Blocks.Item(objBlockRef.Name)

objBlockRef.Delete

objBlock.Delete

...

 

This way you don't keep an entire copy of the
drawing as a block within the drawing which considerably reduces file
size.

 

I hope this helps.


--
Rune Wold
Take the dog for a
walk to reply

 

--
0 Likes
Message 3 of 11

Anonymous
Not applicable
Rune,

A note on your note... 😉

A Redim isn't needed if the point is to be 0,0,0. This will suffice:

Dim varInsPnt(0 To 2) As Double


--
R. Robert Bell, MCSE
www.AcadX.com


"Rune Wold" wrote in message
news:663CF779162FA360EEEDB623D27C1F30@in.WebX.maYIadrTaRb...
| You should check that the prototype drawing has it's base point (origin)
in origo and that UCS is WCS.
|
| A few other comments:
|
| 1:
| You don't really need the dblInsPt variable. It's enough to dim a variant
and then redim it:
| Dim varInsPt as Variant
| Redim varInsPnt(2) as Double
|
| The three cells in this array will have default values 0.0
|
| 2:
| At the end of your sub you should set all objects to nothing.
|
| 3:
| In addition to deleting the block reference, you should delete the block
definition. Get the block definition before you delete the block reference,
delete it after you delete the block reference:
| Dim objBlock As AcadBlock
| ...
| Set objBlock = ThisDrawing.Blocks.Item(objBlockRef.Name)
| objBlockRef.Delete
| objBlock.Delete
| ...
|
| This way you don't keep an entire copy of the drawing as a block within
the drawing which considerably reduces file size.
|
| I hope this helps.
|
| --
| Rune Wold
| Take the dog for a walk to reply
|
| --
0 Likes
Message 4 of 11

Anonymous
Not applicable
Thanks to Rune and Robert for those cool shortcuts.
a question that lingers is:

from Rune:
Dim varInsPt as Variant ' here varInsPt is of type Variant
Redim varInsPnt(2) as Double 'does this create an array of doubles and put
it in the variant???

from Robert:

> A Redim isn't needed if the point is to be 0,0,0. This will suffice:
> Dim varInsPnt(0 To 2) As Double 'unless i'm mistaken this is now an array
of doubles - not a variant containing an array of doubles

since some functions require an array of doubles and some require a variant
containing an array of doubles it might make a difference....or am I missing
something???
0 Likes
Message 5 of 11

Anonymous
Not applicable
Mark,

Wow. I cannot say that I've ever run into a situation where Dim pt0(0 to 2)
As Double caused something the break in the Acad object model, but never say
never, right? I'll let you know if I ever find such a problem (or someone
else will). 😉


--
R. Robert Bell, MCSE
www.AcadX.com


"Mark Propst" wrote in message
news:6DF2FF87690F4C55C708C18BABFEADF5@in.WebX.maYIadrTaRb...
| Thanks to Rune and Robert for those cool shortcuts.
| a question that lingers is:
|
| from Rune:
| Dim varInsPt as Variant ' here varInsPt is of type Variant
| Redim varInsPnt(2) as Double 'does this create an array of doubles and put
| it in the variant???
|
| from Robert:
|
| > A Redim isn't needed if the point is to be 0,0,0. This will suffice:
| > Dim varInsPnt(0 To 2) As Double 'unless i'm mistaken this is now an
array
| of doubles - not a variant containing an array of doubles
|
| since some functions require an array of doubles and some require a
variant
| containing an array of doubles it might make a difference....or am I
missing
| something???
|
|
|
0 Likes
Message 6 of 11

Anonymous
Not applicable
Sorry everyone I had been convinced it was my program at fault. I posted this thread before leaving work last night(South Australian Time) with out doing enough checking. Overnight I realised that the person who created the template probably derived it from a drawing that had been WBLOCKED with an origin other than 0,0. This is indeed the situation. Regards - Nathan
0 Likes
Message 7 of 11

Anonymous
Not applicable
I tried the following and it worked perfectly even though the help specifies a "Variant (three-element array of doubles)".


Dim objBlockRef As AcadBlockReference
Dim dblInsPt(2) As Double
Set objBlockRef = ThisDrawing.ModelSpace.InsertBlock(dblInsPt, "lhouse", 1, 1, 1, 0)

I am currently using AutoCAD 2004 and know that when I originally started programming in VBA Release 14 when I used a "Double (three-element array of doubles)" it raised an invalid argument call.



Thankyou Rune, Robert & Mark for your comments.



Regarding Rune's comment on deleting the block definition I thought 'Stupid Me' although I have used ThisDrawing.PurgeAll to accomplish it.



Thanks a lot - Nathan
0 Likes
Message 8 of 11

Anonymous
Not applicable
A note on your note on my note...

A statically dimensioned double array is fine when you use it as input to a
method or property. However, if you want to get a point property from an
object, you need to use a variant.

To avoid a forest of variables, I tend to reuse them for both input and
output. I find that always using a variant, even if the variable is going to
be used for input only, results in fewer bugs in my code.

A best practice for lacy programmers 🙂

--
Rune Wold
Take the dog for a walk to reply

--
"R. Robert Bell" wrote in message
news:F56964E14B1A6310C29ADB6848CDCF90@in.WebX.maYIadrTaRb...
> Rune,
>
> A note on your note... 😉
>
> A Redim isn't needed if the point is to be 0,0,0. This will suffice:
>
> Dim varInsPnt(0 To 2) As Double
>
>
> --
> R. Robert Bell, MCSE
> www.AcadX.com
>
>
> "Rune Wold" wrote in message
> news:663CF779162FA360EEEDB623D27C1F30@in.WebX.maYIadrTaRb...
> | You should check that the prototype drawing has it's base point (origin)
> in origo and that UCS is WCS.
> |
> | A few other comments:
> |
> | 1:
> | You don't really need the dblInsPt variable. It's enough to dim a
variant
> and then redim it:
> | Dim varInsPt as Variant
> | Redim varInsPnt(2) as Double
> |
> | The three cells in this array will have default values 0.0
> |
> | 2:
> | At the end of your sub you should set all objects to nothing.
> |
> | 3:
> | In addition to deleting the block reference, you should delete the block
> definition. Get the block definition before you delete the block
reference,
> delete it after you delete the block reference:
> | Dim objBlock As AcadBlock
> | ...
> | Set objBlock = ThisDrawing.Blocks.Item(objBlockRef.Name)
> | objBlockRef.Delete
> | objBlock.Delete
> | ...
> |
> | This way you don't keep an entire copy of the drawing as a block within
> the drawing which considerably reduces file size.
> |
> | I hope this helps.
> |
> | --
> | Rune Wold
> | Take the dog for a walk to reply
> |
> | --
>
>
0 Likes
Message 8 of 11

Anonymous
Not applicable
A note on your note on my note...

A statically dimensioned double array is fine when you use it as input to a
method or property. However, if you want to get a point property from an
object, you need to use a variant.

To avoid a forest of variables, I tend to reuse them for both input and
output. I find that always using a variant, even if the variable is going to
be used for input only, results in fewer bugs in my code.

A best practice for lacy programmers 🙂

--
Rune Wold
Take the dog for a walk to reply

--
"R. Robert Bell" wrote in message
news:F56964E14B1A6310C29ADB6848CDCF90@in.WebX.maYIadrTaRb...
> Rune,
>
> A note on your note... 😉
>
> A Redim isn't needed if the point is to be 0,0,0. This will suffice:
>
> Dim varInsPnt(0 To 2) As Double
>
>
> --
> R. Robert Bell, MCSE
> www.AcadX.com
>
>
> "Rune Wold" wrote in message
> news:663CF779162FA360EEEDB623D27C1F30@in.WebX.maYIadrTaRb...
> | You should check that the prototype drawing has it's base point (origin)
> in origo and that UCS is WCS.
> |
> | A few other comments:
> |
> | 1:
> | You don't really need the dblInsPt variable. It's enough to dim a
variant
> and then redim it:
> | Dim varInsPt as Variant
> | Redim varInsPnt(2) as Double
> |
> | The three cells in this array will have default values 0.0
> |
> | 2:
> | At the end of your sub you should set all objects to nothing.
> |
> | 3:
> | In addition to deleting the block reference, you should delete the block
> definition. Get the block definition before you delete the block
reference,
> delete it after you delete the block reference:
> | Dim objBlock As AcadBlock
> | ...
> | Set objBlock = ThisDrawing.Blocks.Item(objBlockRef.Name)
> | objBlockRef.Delete
> | objBlock.Delete
> | ...
> |
> | This way you don't keep an entire copy of the drawing as a block within
> the drawing which considerably reduces file size.
> |
> | I hope this helps.
> |
> | --
> | Rune Wold
> | Take the dog for a walk to reply
> |
> | --
>
>
0 Likes
Message 10 of 11

Anonymous
Not applicable
Thanks!
:-)~
Mark

"Rune Wold" wrote in message
news:210C9C3855EBBEDEB5C7FBD74EEE490B@in.WebX.maYIadrTaRb...
> A note on your note on my note...
0 Likes
Message 11 of 11

Anonymous
Not applicable
Noted. 8^D

--
R. Robert Bell, MCSE
www.AcadX.com


"Rune Wold" wrote in message
news:210C9C3855EBBEDEB5C7FBD74EEE490B@in.WebX.maYIadrTaRb...
| A note on your note on my note...
|
| A statically dimensioned double array is fine when you use it as input to
a
| method or property. However, if you want to get a point property from an
| object, you need to use a variant.
|
| To avoid a forest of variables, I tend to reuse them for both input and
| output. I find that always using a variant, even if the variable is going
to
| be used for input only, results in fewer bugs in my code.
|
| A best practice for lacy programmers 🙂
|
| --
| Rune Wold
| Take the dog for a walk to reply
|
| --
| "R. Robert Bell" wrote in message
| news:F56964E14B1A6310C29ADB6848CDCF90@in.WebX.maYIadrTaRb...
| > Rune,
| >
| > A note on your note... 😉
| >
| > A Redim isn't needed if the point is to be 0,0,0. This will suffice:
| >
| > Dim varInsPnt(0 To 2) As Double
| >
| >
| > --
| > R. Robert Bell, MCSE
| > www.AcadX.com
| >
| >
| > "Rune Wold" wrote in message
| > news:663CF779162FA360EEEDB623D27C1F30@in.WebX.maYIadrTaRb...
| > | You should check that the prototype drawing has it's base point
(origin)
| > in origo and that UCS is WCS.
| > |
| > | A few other comments:
| > |
| > | 1:
| > | You don't really need the dblInsPt variable. It's enough to dim a
| variant
| > and then redim it:
| > | Dim varInsPt as Variant
| > | Redim varInsPnt(2) as Double
| > |
| > | The three cells in this array will have default values 0.0
| > |
| > | 2:
| > | At the end of your sub you should set all objects to nothing.
| > |
| > | 3:
| > | In addition to deleting the block reference, you should delete the
block
| > definition. Get the block definition before you delete the block
| reference,
| > delete it after you delete the block reference:
| > | Dim objBlock As AcadBlock
| > | ...
| > | Set objBlock = ThisDrawing.Blocks.Item(objBlockRef.Name)
| > | objBlockRef.Delete
| > | objBlock.Delete
| > | ...
| > |
| > | This way you don't keep an entire copy of the drawing as a block
within
| > the drawing which considerably reduces file size.
| > |
| > | I hope this helps.
| > |
| > | --
| > | Rune Wold
| > | Take the dog for a walk to reply
| > |
| > | --
| >
| >
|
|
0 Likes