Dear all,
i'am setting my Attachments with a Command:
Set oReferenz = oReferenzen.AddCoincident1(RefFile, "", "", "", msdAddAttachmentFlagCoincidentWorld)
In MSTN 8i was tested whether a Reffile is already attached. In this case i've got oReferenz is Nothing and a Error -2147220766.In a MSTN Connect i am getting a same Attachment with a Suffix Ref, without any Errors.
My Standardsetting for Loading of Attachments is: MS_REF_DEFAULTSETTINGS=display=1,snap=1,locate=1,treatAsElement=0,trueScale=1,useLights=0,saveRelativePath=0,scaleLineStyles=1,ignoreWhenNesting=0,displayRasterRefs=0,newLevelDisplay=fromconfig,nestMode=none,nestDepth=1,nestOverrides=allow,useAnnotationscale=1,plotAs3D=0
How can i prevent of attach the same attachment (which means the same model from the same design file) what is already attached in MSTN Connect?
Thank you.
Hi Mikha,
Mikha Zaslavskiy said:How can i prevent of reloading same Attachments in MSTN Connect?
I have to say I do not quite understand what do you want to achieve. Maybe it's because of mixing term "(already) loading" and "reloading".
Mikha Zaslavskiy said:In MSTN 8i was tested whether a Reffile is already loading. In this case i've got oReferenz is Nothing and a Error -2147220766.
I do not see any such documentation in VBA help, so I guess it's some undocumented side effect.
I also do not understand what does it mean "already loading" in this context. Do you mean to test whether the same attachment (which means the same model from the same design file) is already attached as another reference?
Mikha Zaslavskiy said:i'am setting my Attachments Attachments with a Command:
Ok, that's fine. But when you want to attach a reference, why you want to prevent it to be loaded?
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Hi Jan. Sorry you have right. I meaned already loading or better the same model from the same design file is already attached. I want prevent it to be loaded only if this design file with a same model was already attached. My Tool attached some Attachments from our Ressources. Some Users dont know whether this Data already attached. I will change my Terms in Question. Thank you.
Mikha Zaslavskiy said:I meaned already loading
MicroStation is mostly single threaded synchronous environment and all APIs are solely single threaded, so it's not expected VBA allows you to attach a reference when the same or another is loaded at background.
Mikha Zaslavskiy said:the same model from the same design file is already attached.
General concept and data structures related to references are quite complex, because the same model can be attached several times using different settings, transformations, visualization etc., plus references can be nested. But even when the model is attached several times, it's loaded once only and only one DgnModel instance exists in memory.
In you case it seems the situation is simpler, because when you simply do not allow to attach the same model, it's about to check the direct attachment only.
Mikha Zaslavskiy said:I want prevent it to be loaded only if this design file with a same model was already attached
I guess you have to implement own check. I am not sure whether it's enough to compare whether attachment model is the same as the model you want to attach, but it's how it should be checked: To collect all attached models and to compare them with the model to be attached.
In C++ API it's simpler, because there is dedicated method to check whether two models are the same model or not.
With regards,
I have tried to reproduce this issue, but I get the same result in CE, Update 14. The Run-time errror -2147220766 is commented with "Duplicate logical".This means the same file/model combination may be attached, but then the logical name needs to be unique.This behavior should be the same in V8i and CE.Can you please show us your code to allow me to reproduce the issue you experience - thanks.
Best regards,Artur
Thank you Arthur for your answer.
'RefFile=oReferenz.DesignFile.FullName Public Function Im_Referenzmanager_laden(RefFile As String) Dim oReferenzen As Attachments, obNichtVorha As Boolean Dim oReferenz As Attachment Dim AttachCount As Integer Dim AbschnUmrand As Boolean Dim oMass As Boolean On Error GoTo Err_RefMng Set oReferenzen = ActiveModelReference.Attachments 'Liste vorh. Referenzen If ReferCounter = 0 Then CadInputQueue.SendKeyin "dialog reference; reference attach 0": ReferCounter = ReferCounter + 1 Set oReferenz = oReferenzen.AddCoincident1(RefFile, "", "", "", msdAddAttachmentFlagCoincidentWorld) If Not oReferenz Is Nothing Then oReferenz.DisplayFlag = True 'Referenz sichtbar oReferenz.Redraw 'Referenz aktualis. oReferenz.Rewrite 'Referenz in Datei speichern End If Exit Function Err_RefMng: Select Case err.Number Case -2147220766 'Refenrence is already attached MsgBox "The Reference " & vbCr & vbCr & RefFile & vbCr & vbCr & " is already attached.": Set oReferenz = Nothing: ShowStatus "" Resume Next Case Else MsgBox "Error in Function Im_Referenzmanager_laden " & _ vbCrLf & err.Description, vbCritical, err.Number ' Resume End Select End Function
A user can attach the same file/model multiple times, but each attachment must have a unique Logical Name: Since the same model can be attached many times, the logical name helps you distinguish between references.
Mikha Zaslavskiy said:Set oReferenz = oReferenzen.AddCoincident1(RefFile, "", "", "", msdAddAttachmentFlagCoincidentWorld)
An empty string is a valid Logical Name — as long as no other attachment has the same (empty string) as its logical name. If a model is already attached, and the user has assigned a Logical Name that is not an empty string, then your VBA statement above will succeed, because you are using an empty string for the Logical Name.
Regards, Jon Summers LA Solutions
Hi Jon,
i have tried it with a not empty Logical Name. Vba Statement was not succeed. Regards Mikha.
For Example:Set oReferenz = oReferenzen.AddCoincident1(RefFile, vbNullString, "TSW", "True Scale World", msdAddAttachmentFlagCoincidentWorld)
Artur, can you show me your Code? Thanks.
Mikha Zaslavskiy said:Set oReferenz = oReferenzen.AddCoincident1(RefFile, vbNullString, "TSW",
Attaches a reference using the default model of the specified file with logical name TSW.
Sorry Jon, what are you menaing with unique? I TRYED TO attachTHE EXISTING FILE WITH MY FANTASY LOGICAL NAME. I Dont know whether it is unique. After that i see my first Attachment with a new Logical Name "TSW".