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
Paolo Maggiani said:My desire is to copy each of these cells using OpenDesignFileForProgram.
Prefer OpenDesignFile to OpenDesignFileForProgram! Read this blog.
OpenDesignFile
OpenDesignFileForProgram
Paolo Maggiani said:I read in the Microstation VBA Help that, with OpenDesignFileForProgram, is not possible make use of AddElement (is it correct?).
Why should it not be correct? Read the blog for reasons not to use OpenDesignFileForProgram.
Paolo Maggiani said:My desire is to copy each of these cells from the 3d model of source Dgn to a target Dgn (2D model)
I've suggested elsewhere that a good approach is to attach your source DGN model as a reference to your destination DGN model. Then copy from the reference model to the destination model. That way, MicroStation has already taken care of many settings so you don't have to.
Regards, Jon Summers LA Solutions
Hi Jon Summers,
Jon Summers said:I've suggested elsewhere that a good approach is to attach your source DGN model as a reference to your destination DGN model. Then copy from the reference model to the destination model. That way, MicroStation has already taken care of many settings so you don't have to.
How could I do that?
Is it possible attach reference to a close dgn?
Please , remember my aim is to add elements in a destination dgn each of them in defined position.
Bye,
PM
Paolo Maggiani said:Is it possible attach reference to a close dgn?
You can't do anything with a closed file, whether it's a DGN file, Word file or something else. There's no magic in a DGN file...
Paolo Maggiani said:Is it possible attach reference to a close dgn? My aim is to add elements in a destination dgn each of them in defined position.
I suggest that you first try this manually: attach the DGN model, with elements to be copied, to your active model. Then use MicroStation's Copy tool to copy from the reference into the active DGN model. Note that the Copy command works when a fence is active. Practise as a MicroStation user will inform your coding as a MicroStation developer.
Jon Summers said:You can't do anything with a closed file, whether it's a DGN file, Word file or something else. There's no magic in a DGN file. A file must be open for read in order to view its contents. A file must be open for write in order to modify its contents
Ok, but we come back to the problem: I don't want to really open the destination file (OpenDesignFile): I wish user don't see anything...
Paolo Maggiani said:I wish user don't see anything
VBA developers often state something similar. The real question is, "Do your users care that something is happening automatically?"
First, get your app working. Second, ask users for comments. If a user tells you: "I don't want to see MicroStation while this automatic process continues!" then is the time to figure out how to make MicroStation invisible.
It is true Jin, but......in this case I am developer and user too. :-)
Anyway, I should open the file with OpenDesignFIle, attach a reference and use the CopyElement or AddElement (which one?), then detach the file, right?
Paolo Maggiani said:I should open the file with OpenDesignFIle, attach a reference and use the CopyElement or AddElement (which one?), then detach the file, right?
Correct! Use CopyElement, passing a CopyContext. From VBA help: CopyElement's default behavior is to add the element to the model. There's example code in the help topic for CopyElement.
CopyElement
CopyContext