Hi,
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.
Should probably move this message over to the programming forum:
communities.bentley.com/.../microstation-programming---forum
My mistake (new here) somebody has kindly moved this.
Its worth noting, that some drawings my code works perfectly. Some its off by a semi-consistent offset (x and y).
Hi John,
John Burland said:I have a frustrating issue where VBA
please read and follow the best practices and share a recommended set of information. You do not provide any information what product and version (exact build number preferably) you use. Also, there is no information what data do you use (are files, active and references, DGN V8, DGN V7 or DWG?).
John Burland said:Ideas?
It's hard to say without knowing more information.
When you have working and not working sets, you should analyze what is different and what is "full chain" of settings, from units + resolution in referenced model (plus how global origin is set etc.), through reference attachment parameters (scale, is georeferenced, type of attachment...), to active model settings (again, units + resolution, GO...).
John Burland said:My mistake (new here) somebody has kindly moved this.
When you accidentally create a post in wrong forum, you can move it yourself. Use More > Move tool, available under your original post.
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
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.
GetMasterToReferenceTransform
GetMasterToReferenceTransformGetReferenceToMasterTransform
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.
ReferenceAnalysisWithVba.zip
The master model has two attachments
I've attached a VBA project to show some attachment settings.
AnalyseAttachments.zip
clsAttachmentAnalyser
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'.