[V8i - VBA] CopyElement problems

Good morning friends,

in a 3D model, I have some 3D objects (Cells).  I did "Visible Edge Export" of each of them on the XY, XZ and YZ planes. And then Flatten Curve.

My desire is to copy each of these cells (They are cells because the lines obtained with Flatten Curve have been grouped - GROUP SELECTION command) from the 3d model of source Dgn to a target Dgn (2D model) using OpenDesignFileForProgram.

I read in the Microstation VBA Help that, with OpenDesignFileForProgram, is not possible make use of AddElement (is it correct?).

Then I utilised CopyElement, but I got some problems:

1. CellElements are 100 times greater (Both files, source and target, have the same working unit and active scale is set to 1 for x, y and z)

2. I got, in the target file, only one cell for each originary 3D cells in the right "persective" (please see the attached image) : top and left are wrong.

3. Cells Position, in the target file are not the asked ones (I suspected this problem could be linked to n.1 problem)

I tried to do a lot of attempts to solve those problems, without luck...

I insert the last one here (where I also added cells to source file too, to see if AddElement (Instead of CopyElement) works well...and all was right).

Sub CopyToSmartSketch()
    Dim myDgn As DesignFile
    Dim myCopyContext As New CopyContext
    
    ActiveDesignFile.Models("Default").AddElement myCellToExchange
    
    Set myDgn = OpenDesignFileForProgram("C:\Users\Paolo\Desktop\Celle\smartSketch.dgn", False)
    
    myCopyContext.ChangeUnits = True
    myCopyContext.MatchDimensionToDestination = True
    myCopyContext.LevelHandling = msdCopyContextLevelByUserPreference
    myCopyContext.ViewForFlattening = myPlane
    
    myDgn.Models("Default").CopyElement myCellToExchange, myCopyContext
    
    myCellToExchange.Origin.X = myOriginX
    myCellToExchange.Origin.Y = myOriginY
    
    myCellToExchange.Rewrite
    myCellToExchange.Redraw
    
    myDgn.RewriteLevels
    myDgn.Save
    myDgn.Close
End Sub

I searched on the web: I found a LA Solution to copy objects from 3D model to a 2D one, but (I didn't try it) I would like to write my own one.

Thanks a lot.

Best regards, 
Paolo

Parents Reply
  • I don't want to really open the destination file (OpenDesignFile): I wish user don't see anything...

    I want and wish (and also don't want in other cases) a lot of things. Many from them are too far from reality, but the rest can happen ... through doing, not asking.

    Ok, but we come back to the problem

    That's not the problem. You are trying to focus on "I'd like to have" step X, when steps A, B, C... are not solved properly yet.

    Anyway, I should open the file with OpenDesignFIle

    My feeling is that this discussion is spinning in circles.

    The approach based on best developers' practices was provided and Jon described it simply (I only repeat the same facts to express I also think this is the only working and wise option):

    • Simulate the process manually, using active model as target, copy element(s) from attached reference.
    • Implement these step in VBA (because copying from reference to active model represents the most simple situation and problems can be discussed).
    • When everything will work perfectly (seriously, everything! including orientation, position, workflow...), let's start to discuss whether it's possible to do the same at background.

    When you decide to do not follow these old programming best practices (split problems into tiny ones, do it simple at first, write tons of test code to evaluate concept and increase own understanding), it's fine, but it's longer and more exhausting way.

    Regards,

      Jan

Children
No Data