Writing a VBA to deattach and then reattach a large amount of reference files. I have all the information except running into problems with reference files that have been
moved. I would like to get their current location and reattach them. Also the display seems not to be working. Below is most of my code.
'Getting information about attached reference files
For Each att In ActiveModelReference.Attachments
If att.DisplayFlag = False Then ReferenceFiles(x).Display = False att.DisplayFlag = True Else ReferenceFiles(x).Display = True End If
ReferenceFiles(x).filename = att.DesignFile.FullName ReferenceFiles(x).Model = att.AttachModelName ReferenceFiles(x).Description = att.LogicalDescription ReferenceFiles(x).LogicalName = att.LogicalName ReferenceFiles(x).Masterorgin = att.MasterOrigin ReferenceFiles(x).RefOrgin.Y = att.MasterOrigin ReferenceFiles(x).RefOrgin = att.AttachmentOrigin x = x + 1 Next
'Reattaching reference files
Do Until x = 1000 If ReferenceFiles(x).filename <> "" Then attParent.Attachments.Add ReferenceFiles(x).filename, ReferenceFiles(x).Model, ReferenceFiles(x).LogicalName, ReferenceFiles(x).Description, ReferenceFiles(x).RefOrgin, masterpoint, True, ReferenceFiles(x).Display End If x = x + 1 Loop
Hi Larry,
the method .reattach allows to reattach without previous detaching. This would also allow to replace the files. To get the location the method .MasterOrigin may be used.Maybe you may want to test something like this:
Dim oAtt As Attachment For Each oAtt In ActiveModelReference.Attachments Debug.Print "Placed in Master at (xy): " & Str(oAtt.MasterOrigin.X) & " , " + Str(oAtt.MasterOrigin.Y) oAtt.Reattach oAtt.AttachName, vbNullString Next If this doesn´t help, please let us know why to deattach and attach new all the reffiles.Best regards,Artur
Arthur, I need to rearrange the reference files is the reason I'm deattach and attaching the files. The problem I'm running into is that on some our division have their working units as feet/feet in which it vba works fine. Other divisions work have there units feet/inches and the master origin doesn't report correctly.
Larry WilsonLWilson@LJBinc.com
I would try to avoid detaching reffiles, as settings like level overrides are lost with detaching a reffile, while .reattach keeps these settings.
Would it be helpful to know the Unit labels for master / sub units and depending on the value interpreting the values as foot / inch and using the .move method to move the reffiles:
Dim oMaster As MeasurementUnit Dim oSub As MeasurementUnit oMaster = ActiveModelReference.MasterUnit oSub = ActiveModelReference.SubUnit Debug.Print oMaster.Label & " " & oSub.Label
The reference box offset is the value the reference is moved against the master. It is the same value you get with the method .MasterOrigin.It is not clear to me what the values for origin ( in your example x=163.5969277 and y=179.500000) means here and how you get these values.Could you please upload a small example with master + reffile, which demonstrates the problem?Thanks
Artur