Author Topic: (Microstation) Creating Cell libraries with VBA  (Read 6450 times)

0 Members and 1 Guest are viewing this topic.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
(Microstation) Creating Cell libraries with VBA
« on: March 08, 2008, 11:23:50 PM »
Ok Ladies and Gents (others welcome as well) .. my first question of 2008 will be something I have pondered for a while and hopefully with the great minds here we can devise a solution ...

I have a whole library of autocad blocks that I must import into cell libraries. Now let me explain the problems I have faced before I am given specifics on how to create the darn things ... already had a ton of trial and error and found the following to be true ...

We need the cells aka blocks to be unshared (a concept foreign in AutoCAD) thus for assemblies where there are nested cells, I must open each cell independently, drop all shared cells to normal cells and save the file. Not too dificult for a dozen or so cells with a few nested cells, however, we are talking about hundreds of cells with some of them having nearly 50 shared cells ... this would be a daunting task for anyone .. monumental even.

Next issue ... AutoCAD blocks are inserted using insbase as the origin of the block, when placing a cell in microstation, insbase is also observed if the cell was imported from a dwg, however, future editing of the drawing when attempting to programmatically alter the cell, microstation ignores insbase and substitutes 0,0,0 as the origin, thus when attempting to manipulate cells, the result is often unpredictable.

Finally, the importing of dwg or dgn files directly into a cell library causes some other issues, namely, the specific model must be selected manually, the cell type may need to be modified and descriptions may need to be added.

This brings me to the point I am at today ...

I have created a VBA macro that opens all of the autocad drawings in a specific folder, moves all geometry in the drawing in modelspace from the current insbase to 0,0,0 and resets insbase to 0,0,0, zoom extents, then wblocks the drawing to purge layers, unreferenced blocks, linetypes, textstyles, etc. This works exactly as planned without hitch .. remember I am an AutoCAD guy, not a Microstation guy .. but I am muddling through ...

Now, on the microstation side I have created a VBA macro that opens all the DWG files in a specific folder, saves them as a DGN, sets "Model" as the active model, deletes all other models (i.e. Layout1 etc), drops all shared cells to geometry and recreate them as normal cells while deleting the shared cells, changes the name of the default model "Model" to the drawing name, changes the description of the model to the drawing name, saves the dgn and repeats until all dwg files are created as dgn files. Unfortunately this seems to be the only method by which I can delete the extra layouts as you can't delete them in DWG files .. at least I havn't been able to.

The final piece of this puzzle is what is eluding me ... I need to import all of the models in the dgn files with the same name as the dgn file to a cell library (I know a cell library is simply a design file with multiple models) ...
Doing this manually is as simple as opening the models window, selecting the "import model" button, select the dgn, select the model, and click ok ... imagine doing this thousands of times over ... I can easily see myself missing a file or worse, importing a model twice with different names ... I don't want that to happen ...

So, I need help ... help in figuring out a method by which I can automate the automatic importing of the default model into the current design file.

I tried to record a macro of the process needed to import them, but the method would still require the manual selection of buttons ...

VBA seems to be the best at handing this, but if someone has a MDL app that will do it or is close, that would be ok too.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

pmvliet

  • Guest
Re: Creating Cell libraries with VBA
« Reply #1 on: March 10, 2008, 01:39:08 AM »
I've read this twice and probably have to read it a few more times. It is also 1:30am.

maybe it's in there, or maybe it's my not fully understanding.

a) you have 100 autocad blocks in 100 autocad files.
b) you then are basically importing/redrawing into 100 microstation files.
c) you then want to create one cell library containing 100 microstation blocks (100 models in one microstation file)

you've accomplished a) and b) and need to automate c)?

Pieter

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Creating Cell libraries with VBA
« Reply #2 on: March 10, 2008, 07:56:35 AM »
Yes on A, except it could be more like hundreds
Yes on B
Yes on C

Now for another problem I have found ...

These blocks are drawn 1:1, when importing them into Microstation, inches are assumed as the units and mils as the sub-units. This would be fine, except when I use them in a drawing in Microstation, with the units set the same, the darn things are not quite 1/40th the size (according to dimensions) as they should be.

No amount of unit adjustments seem to get it right. Are AutoCAD inches and Microstation inches not the same?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

kindra

  • Guest
Re: Creating Cell libraries with VBA
« Reply #3 on: March 10, 2008, 08:32:51 AM »
Keith,

Lofty goals there, sir. I wish you luck, but as I'm sure you are painfully aware by now, MS and ACAD usually don't play nice together. As far as automating the conversion process, I am digging in my resources to find something to help, but quite frankly this sounds a bit out of my league. But as far as the inches, you're kind of right - MicroStation inches aren't quite the same as ACAD. MicroStation's units (by default) are set to survey feet, which is .999998 of an international foot. This makes for a slight discrepancy between MS and ACAD units. But if they're coming in at 1/40th of what they should be, well, I've got nothin'.

I'll get back to you after digging through by books - sorry I couldn't be more help!

K

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Creating Cell libraries with VBA
« Reply #4 on: March 10, 2008, 09:04:19 AM »
I have completed the basic procedural things, right now I use both AutoCAD and Microstation for the process, although I could see myself using only Microstation in the future if I can get it all sussed out.

In AutoCAD the procedure is as follows:
Using the "ReturnFolder" module found elsewhere on theswamp, a folder is returned to the function. All dwg files in the folder are enumerated and one by one they are: opened, all objects moved from insbase to 0,0,0, insbase reset to 0,0,0, all objects moved to layer 0, CLAYER set to 0, CECOLOR set to BYLAYER, zoomed extents and wblocked.

In Microstation the process is:

Using the "ReturnFolder" module found elsewhere on theswamp, a folder is returned to the function. All dwg files in the folder are enumerated and one by one they are: opened, saved as DGN-V8, "Model" set to active, extra models deleted, "Model" renamed to DGN name, model description set to DGN name, and saved.

Will it help to set reset the drawing units before resaving the DGN? Can I reset the drawing units programmatically?

Which brings me to the spot I am right now ... can the process of importing models into a DGN file be accomplished programmatically?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

pmvliet

  • Guest
Re: Creating Cell libraries with VBA
« Reply #5 on: March 10, 2008, 01:19:38 PM »
I just used a 100 as a placeholder. I understand that you have thousands of things to go through...

The working unit resolution in Microstation will change your dimensions.... I'm sure you know that.
This can be a real headache. I was going from Microstation to Autocad and each cell in a cell library
can have a different working unit, they would all come in at different sizes... A real pain

I think this one is above my knowledge... unless I fiddle with things and play with it.
Your programming skills are way more advanced then mine

I'm working on a microstation job for the next few days and if anything hits me in the head
I'll chime back in.

Pieter


Arizona

  • Guest
Re: Creating Cell libraries with VBA
« Reply #6 on: March 10, 2008, 02:00:29 PM »
Keith,

I believe what you are asking is possible.
You simply want to import a folder of files individually into separate (named?) models of a dgnlib (or cell library). The process is the same.
Tomorrow I'll see what I can come up with for you to at least get you started. I have done this process manually many times and I could see a use for this myself. Is this for V8/XM?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Creating Cell libraries with VBA
« Reply #7 on: March 10, 2008, 02:09:57 PM »
it is V8
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Arizona

  • Guest
Re: Creating Cell libraries with VBA
« Reply #8 on: March 11, 2008, 08:15:35 AM »
This is some of what I found, hope it helps...

Function CreateNewModel(strName As String) As ModelReference
    Dim template As ModelReference
   
    Set template = ActiveDesignFile.DefaultModelReference
    With template
        Set CreateNewModel = ActiveDesignFile.Models.Add(template, strName, "Added " & Now, .Type, .Is3D)
    End With
End Function

The new element will not become part of the design file until it is added to a model (using AddElement on the appropriate ModelReference object).

.......
    Dim oCell As CellElement
    Set oCell = CreateCellElement1(...)
    '
    '  ...Set other properties of oArc, if you wish...
    '
    ActiveModelReference.AddElement oCell