Hi,
I have a cell library (which is attached). Cell origins are given wrong (far from cells) by user in cell library. I am trying to move cell origins as bottom left coordinates of cabinets using below VBA code. VBA code works properly without any error but at the end cell origins are not set properly. After VBA code ended, MicroStation waits for a click every time. Can you tell me what is wrong?
' Fix cell origins to the bottom back of each cabinet
Sub CellOriginFix()
' How to move the origin of a cell in the cell library. ' 1. Open the Cell Library ' 2. Go to File > Models and choose the Cell/Model that you want to modify. ' 3. Key-in: choose all;move extended;/d;xy=0,0,0 ' 4. Select the point where you want the origin of the cell to be.
' This method is taken from http://communities.bentley.com/products/microstation/w/microstation__wiki/13946.move-the-origin-of-a-cell
Dim theModel As ModelReference Dim theRange As Range3d Dim thePoint As Point3d For Each theModel In ActiveDesignFile.Models theModel.Activate ' Activate model theRange = theModel.Range(False) ' Get model range ' Define cell origin point according to model range thePoint.X = theRange.Low.X thePoint.Y = theRange.High.Y thePoint.Z = theRange.Low.Z 'MessageCenter.AddMessage thePoint.X ' Set cell origin CadInputQueue.SendKeyin "choose all;move extended;/d;xy=0,0,0" ' Click origin CadInputQueue.SendDataPoint thePoint, 1 ' Send a reset to the current command CadInputQueue.SendReset
CadInputQueue.SendCommand "FIT VIEW EXTENDED 1" CadInputQueue.SendCommand "FIT VIEW EXTENDED 2" CadInputQueue.SendCommand "FIT VIEW EXTENDED 3" CadInputQueue.SendCommand "FIT VIEW EXTENDED 4"
Next CommandState.StartDefaultCommand
End Sub
test.cel
Hi Ahmet,
Unknown said:I am trying to move cell origins
As others noted already, despite of your want to move the cells origins, from a code perspective you have to move all elements to the model origin. It's a terminology issue not related to your code, but in my opinion it's wise to be strict and precise as it helps to define better what you want to do.
Unknown said:Can you tell me what is wrong?
Hmmm ... frankly ... the code is not good. It's not about the functionality, others already provided some advices what to change, but about the style. I think I understand why it's written this way, to simulate user's activity using key-ins is straightforward and simple approach, but quite fragile and not recommended ... and in fact it's not VBA, but just a script written in VBA environment.
To not criticise only, please check the attached code, it should do what you want, but in more "VBA style" in my opinion.
With regards,
Jan
move-cell-origin.mvba
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Answer Verified By: Sedat Alis
Unknown said: To not criticise only, please check the attached code, it should do what you want, but in more "VBA style" in my opinion.
Hi Jan,
Thank you so much. :) You are right, your code is in VBA style and it is very fast too.
Kind regards,
Sedat AlisAEC Technology Inc.