I have a frustrating issue where VBA is not reading the reference file offset correctly. I'm working with a bunch of existing drawings and need to know this for inserting some cell's in bulk. Some drawings it works perfectly but not for others. Ive checked scales etc as far as I know they are OK.
Ideas? Screen shots below showing the X offset in the reference file dialog vs the VBA result.
John Burland wrote: Microstation noob, I miss AutoCAD :-(.
Welcome to the MicroStation Programming Forum!
John Burland said:I have a frustrating issue where VBA is not reading the reference file offset correctly
MicroStation Help tells us: Offset — Displays and sets the distance between the global origin of the reference from the global origin of the parent file, measured in units of the parent file. If the parent is 2D, Offset X and Y values are displayed. If the parent is 3D, Offset X, Y, and Z values are displayed.
OffsetArray (0) = oAtt.MasterOrigin.X
You're not calculating the offset, but reading the master origin. Try something like this...
Dim offset As Point3d
offset = Point3dSubtract (oAtt.MasterOrigin, oAtt.AttachmentOrigin)
OffsetArray (0) = offset.X
Depending what you're attempting to achieve, methods GetMasterToReferenceTransform and GetMasterToReferenceTransformGetReferenceToMasterTransform may be useful.
Regards, Jon Summers LA Solutions
Thanks, on another drawing the offset shown in the drawing properties is 0.From the code im getting the following numbers. This would imply there is a scale factor for the attachment of 100. What I don't understand is why there is a MasterOrigin.X offset even though the global origin is zero. If I move the reference file (change the offset in the dialogue box) the Master Origin value tracks perfectly, just with the offset of -7.49. GlobalOrigin.X = 0AttachmentOrigin.X = -7497.22674003187MasterOrigin.X = -7.49722674003187
The attachment files I have (Drawing border frame) are not perfectly centered, with an X offset of exactly -8, not 7.49 - this could be the cause of this, and maybe a units issue causing the difference between the -8 offset in the reference file and the -7.49 recorded in the drawing. Here's what Bentley had to say:"This should be caused by shifted GlobalOrigin in the attachments. Additionally to oAtt.MasterOrigin also oAtt.GlobalOrigin should be analyzed. Please note the values provided for GlobalOrigin are in UOR instead of working units."
John Burland said:on another drawing the offset shown in the drawing properties is 0
Is that unexpected? Doesn't that mean that it's a coincident attachment?
This should be caused by shifted GlobalOrigin in the attachments. Additionally to oAtt.MasterOrigin also oAtt.GlobalOrigin should be analyzed. Please note the values provided for GlobalOrigin are in UOR instead of working units.
The rules of reference attachments, combined with the possibility of a non-zero global origin (GO), are tricky. You need to set up some experimental data to cement your understanding and to test your code.
Create some attachments first by copying the original, and set the GO to zero. Then create several attachments of the same model at known offsets so you can analyse the math easily and confirm that your VBA is working.
Next, create a copy of the attachment and modify its GO by a known amount, and attach with several offsets so you can analyse the math easily and confirm that your VBA is working.
If you really want to stretch your understanding, repeat the above with the attachment rotated, scaled or both rotated and scaled. It's then that methods GetMasterToReferenceTransform and GetMasterToReferenceTransformGetReferenceToMasterTransform become especially useful.
I've attached a DGN file that may help.
The master model has two attachments
I've attached a VBA project to show some attachment settings.
Answer Verified By: Robert Hook
Hi Jon,Just thought I would say thanks for your help, this will save me a lot of time (inserting a 'stamp' in bulk to client drawings that are a mix of rotation, scale, offset etc.The GetReferenceToMasterTransform method was the step I was missing. I have found a few drawings that have been rotated, so as you suggest ill have a play around with your example so I understand the rotation impacts.Thanks once again.
John Burland said:Just thought I would say thanks for your help
I'm pleased to read that your understanding of VBA is advancing!
Please mark your question as 'Answered'.