VBA Merge Reference

Hi All,

Trying to Merge a reference file into the Default Model and really struggling to get it working.

After reading alot on these forums and in the VBA help, I have found that there is no simple merge option in VBA, and that the best way to do it by copying, but haven't been able to find a working example. Can anyone guide me in the right direction?

Am i right in saying that i need to select everything from the reference, then use the CopyElement command to copy it to the new model?

At the moment, I can't get anything to select, let alone copy. I have done a fair bit of VBA work, but usually when selecting elements i narrow it down using ElementScanCritera, but in that there isn't an option to include all types, so im assuming by not setting one its defaulting to select everything? :/

This is a small part of a bigger project, I have already attached the Reference i want to attach and have created a new Model for it to merge into... just cant get the job done!

Thanks in advance!

Using PowerDraft 08.11.07.443 on XP

Parents
  • Unknown said:
    I have found that there is no simple merge option in VBA, and that the best way to do it by copying

    What would a 'simple merge' involve, if it's not copying from the reference to the active model?

    Unknown said:
    ... use the CopyElement command ...

    CopyElement isn't a command; it's a VBA method.  The word command has a particular meaning in MicroStation, and to maintain clarity it's best to stick with recognized nomenclature.

    Unknown said:
    I need to select everything from the reference, then use the CopyElement method to copy it to the new model?

    Yes.  Although the idiom for 'select everything from the reference' is the scanner.  Use ModelReference.Scan to collect all elements from an attachment and copy them to the active mode.  Create a CopyContext before you start the scan and use it for each copy operation.

    Unknown said:
    Usually when selecting elements i narrow it down using ElementScanCritera, but in that there isn't an option to include all types

    By default the scan criteria include everying, so you don't have to do anything to include all element types.  Be aware that the scanner will by default collect non-graphical elements, which you may not want.  Use ScanCritieria.ExcludeNonGraphical to impose that restriction.

     
    Regards, Jon Summers
    LA Solutions

  • Thanks for the reply jon

    Unknown said:

    What would a 'simple merge' involve, if it's not copying from the reference to the active model?

    Was meaning  something along the lines of

    oReference.MergeToMaster

    A one-step procedure that uses the same term as MicroStation

    My bad about the terminology... yesterday was a loooong day!!

    When I have tried to scan everything it has picked up the Non Graphical items you spoke about, so now i can get rid of those, but it didn't pick up much else. Can the selecting of the file be done after the files has been referenced into MicroStation?

    Or do i need to use the OpenDesignFileForProgram method to grab what i need?

    Is the "paste" a seperate thing or when copying does it automatically copy into the ActiveModel?

    Sorry for the barrage of questions, have been playing around with this for a while and can't much working.

  • Jon suggested you to use correct terminology, but you still mention some 'paste' method and so. In VBA there is no 'paste' method - it is really a separate thing. VBA is a scripting/programming language, so all tasks need to be programmed, or you can invoke a MicroStation command.

    Merging reference to master in VBA is simple as follows:

    Option Explicit

    ' function makes copy of all graphical elements from srsRef into dstModel
    Sub CopyGraphicalElements(dstModel As ModelReference, srcRef As Attachment)
      ' we want to copy only graphical elements now
      Dim sc As New ElementScanCriteria
      sc.ExcludeNonGraphical
      
      ' we need copy context
      Dim cc As New CopyContext
      cc.LevelHandling = msdCopyContextLevelCopyIfNotFound

      ' create enumerator
      Dim ee As ElementEnumerator
      Set ee = srcRef.Scan(sc)
      
      ' copy elements
      While ee.MoveNext
        dstModel.CopyElement ee.Current, cc
      Wend
     
    End Sub

    ' routine makes copy of all graphical elements
    ' from attachments into active model
    Sub MergeAllReferences()
      Dim att As Attachment
      For Each att In ActiveModelReference.Attachments
        CopyGraphicalElements ActiveModelReference, att
      Next
    End Sub

    Answer Verified By: Rob Golding 

  • Unknown said:

    something along the lines of oReference.MergeToMaster

    Please don't take my comment below as a criticism — it's intended to provoke you to think more deeply about the purpose of programming.

    Analyse what you've written in the context of my earlier comment.  What would your Attachment.MergeToMaster do if it's not scanning and copying?

    As a programmer you have to peer and poke around inside MicroStation.  That peering and poking occurs at a much more intimate level of detail than seen by a regular user.

     
    Regards, Jon Summers
    LA Solutions

  • Unknown said:

    something along the lines of oReference.MergeToMaster

    Please don't take my comment below as a criticism — it's intended to provoke you to think more deeply about the purpose of programming.

    Analyse what you've written in the context of my earlier comment.  What would your Attachment.MergeToMaster do if it's not scanning and copying?

    As a programmer you have to peer and poke around inside MicroStation.  That peering and poking occurs at a much more intimate level of detail than seen by a regular user.

    [/quote]

    I haven't taken anything as criticism, the reason why i come onto these forums is to learn from experts like yourself, then hopefully someday i can help someone else.

    Dan's post above has done exactly what i wanted. My code that i pieced together from the VBA Help examples, forum posts etc wasn't far off, infact it was missing something pretty small but enough for it not to work.

    But in saying that I now have another problem with the bigger project as described above... but its not to do with merging so i'll make a new thread as i have the answer i was looking for.

Reply
  • Unknown said:

    something along the lines of oReference.MergeToMaster

    Please don't take my comment below as a criticism — it's intended to provoke you to think more deeply about the purpose of programming.

    Analyse what you've written in the context of my earlier comment.  What would your Attachment.MergeToMaster do if it's not scanning and copying?

    As a programmer you have to peer and poke around inside MicroStation.  That peering and poking occurs at a much more intimate level of detail than seen by a regular user.

    [/quote]

    I haven't taken anything as criticism, the reason why i come onto these forums is to learn from experts like yourself, then hopefully someday i can help someone else.

    Dan's post above has done exactly what i wanted. My code that i pieced together from the VBA Help examples, forum posts etc wasn't far off, infact it was missing something pretty small but enough for it not to work.

    But in saying that I now have another problem with the bigger project as described above... but its not to do with merging so i'll make a new thread as i have the answer i was looking for.

Children
No Data