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
Ahmet Sedat ALIS said:' Define cell origin point according to model range thePoint.X = theRange.Low.X thePoint.Y = theRange.High.Y thePoint.Z = theRange.Low.Z
Are you sure that's what you want?
Regards, Jon Summers LA Solutions
Jon Summers said: Ahmet Sedat ALIS ' Define cell origin point according to model range thePoint.X = theRange.Low.X thePoint.Y = theRange.High.Y thePoint.Z = theRange.Low.Z Are you sure that's what you want?
Ahmet Sedat ALIS ' Define cell origin point according to model range thePoint.X = theRange.Low.X thePoint.Y = theRange.High.Y thePoint.Z = theRange.Low.Z
Exactly. :) This brings me bottom-back-left point of the cabinet.
Kind regards,
Sedat AlisAEC Technology Inc.
Brien Bastings said:The cell origin is 0,0,0...so you want to move the geometry relative to the location that is to become the new cell origin to 0,0,0. i.e. you've got your points backwards...what your code is doing is moving the selection set elements relative to 0,0,0. If instead "thePoint" was used to accept the selection set/define the point to move "from", and 0,0,0 was used as the move "to" point you should get the result you want. You could also keep the current point order and negate "thePoint"...but I think that's just needlessly confusing.
Thank you Brien, this is a good point. But when I do this job manually, I am clicking the same point that I calculated as thePoint.
What is the reason of MicroStation waits for a single click at the end? It seems it can't complete move operation.
Hi Ahmet, Have you tried appending keyin RESET at the end of your keyin command queue? HTH, YongAn
Hi Ahmet,
Ahmet Sedat ALIS 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.
Ahmet Sedat ALIS 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
Jan Slegr 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.
Yongan.Fu said: Have you tried appending keyin RESET at the end of your keyin command queue?
Have you tried appending keyin RESET at the end of your keyin command queue?
Hi Yongan,
You are right, this may solve the last click problem but my code still needs to be fixed. :)