• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. Skill code for aligning any shape or instance at the midpoint...

Stats

  • Replies 6
  • Subscribers 143
  • Views 1819
  • Members are here 0

Skill code for aligning any shape or instance at the midpoint of the ruler.

yogeshjaiswalCAD
yogeshjaiswalCAD 22 days ago

Greetings Team,

Thanks for always being there for help. I need help with the skill code for aligning any shape or instance at the midpoint of the ruler in Virtuoso Layout Editor. 

I have shared the concept reference. 

; that depend on the exact view and object you're working with.

; 1. Get the selected object's bounding box
object_bBox = selected_object~>bBox

; 2. Calculate the object's center
object_mid_x = (car(object_bBox) + cadr(object_bBox)) / 2
object_mid_y = (cadr(object_bBox) + caddr(object_bBox)) / 2
object_mid_point = list(object_mid_x object_mid_y)

; 3. Define the target ruler midpoint (this part is highly dependent on your setup)
; For example, if you want to center it in the current view's X-dimension
cv = geGetEditCellView()
view_bBox = cv~>bBox
ruler_mid_point_x = (car(view_bBox) + cadr(view_bBox)) / 2
ruler_mid_point_y = (cadr(view_bBox) + caddr(view_bBox)) / 2 ; Or a specific ruler Y

; 4. Calculate the displacement needed to move the object's center to the ruler's midpoint
dx = ruler_mid_point_x - object_mid_point~>x
dy = ruler_mid_point_y - object_mid_point~>y

; 5. Move the object using a movement function (replace with actual function like leMoveFig)
; You'll need to select the object and then call a function to move it by (dx, dy)
; Example: leMoveFig(list(selected_object) list(dx dy) nil) ; Incorrect syntax for illustration

Please share with me any skill code for aligning any shape/instance at the midpoint of the ruler.
I will be grateful for your help. Please help in!

With warm regards,

Yogesh Jaiswal

  • Cancel
  • Sign in to reply
  • Aurel B
    Aurel B 22 days ago

    Hi,

    This should do what you described:

    (defun cst_align_to_ruler
           ( @key  ( objects (geGetSelectedSet) )
             @rest _
             )
      "Align all OBJECTS on ruler center.
    Exactly one ruler has to be selected"
      ;; Fetch ruler
      (letseq ( ( rulers (setof obj objects (equal "ruler" obj->objType)) )
                ( ruler  (or (car rulers) (error "No ruler is selected")) )
                )
        (assert (not (cdr rulers))       "More than one ruler is selected")
        (assert (equal 2 ruler->nPoints) "Ruler has more than two points" )
        (destructuringBind ( ruler_x ruler_y ) (centerBox ruler->points)
          ;; Browse all objects except rulers (other object types could be filtered here...)
          (foreach obj objects
            (unless (member obj->objType '( "ruler" ))
              (destructuringBind ( obj_x obj_y ) (centerBox obj->bBox)
                (dbMoveFig obj obj->cellView (list ruler_x-obj_x:ruler_y-obj_y "R0" 1))
                );dbind
              ));unless ;foreach obj
          );dbind
        ));letseq ;fun
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Andrew Beckett
    Andrew Beckett 22 days ago in reply to Aurel B

    I just wrote a slightly different implementation because the requirements were slightly ambiguous. In my case if more than one object was selected, if moves the centre of the entire set (other than the ruler) to the center of the ruler. I didn't bother checking that the ruler had only two points - that could easily be added.

    I also do a bit of messing around because if you're moving more than one object, you shouldn't move child objects which are attached to a parent that is also being moved (otherwise it moves twice).

    Anyway, with this and Aurel's code, you have a couple of alternatives to choose from (his is shorter because it doesn't worry about child objects or finding a common centre).

    procedure(CCFalignToRulerCenter(@optional (objects geGetSelSet()))
      let((rulers nonRulers rulerCenter objCenter transform
            (objTable (makeTable 'objects nil)))
        ;--------------------------------------------------------------------
        ; First pass through objects to find rulers and record
        ; potential objects to move
        ;--------------------------------------------------------------------
        foreach(obj objects
          if(obj~>objType=="ruler" then
            rulers=cons(obj rulers)
          else
            objTable[obj]=t
          )
        )
        when(!rulers || cdr(rulers)
          error("Must have exactly one ruler in the selected set")
        )
        ;--------------------------------------------------------------------
        ; Filter the remaining objects to omit those where the parent 
        ; (i.e. the object attached to) is also in the set
        ;--------------------------------------------------------------------
        foreach(obj objTable
          unless(objTable[obj~>parent]
            nonRulers=cons(obj nonRulers)
          )
        )
        unless(nonRulers
          error("Must have at least one object selected to move")
        )
        ;--------------------------------------------------------------------
        ; Find the center of the ruler and all the other objects
        ;--------------------------------------------------------------------
        rulerCenter=centerBox(car(rulers)~>bBox)
        destructuringBind(((ollx olly) (ourx oury)) car(nonRulers)~>bBox
          foreach(obj cdr(nonRulers)
            destructuringBind(((llx lly) (urx ury)) obj~>bBox
              ollx=min(ollx llx)
              olly=min(olly lly)
              ourx=max(ourx urx)
              oury=max(oury ury)
            )
          )
          objCenter=centerBox(list(ollx:olly ourx:oury))
        )
        ;--------------------------------------------------------------------
        ; Calculate transform and move all the objects
        ;--------------------------------------------------------------------
        transform=list(mapcar('difference rulerCenter objCenter) "R0" 1)
        foreach(obj nonRulers
          dbMoveFig(obj obj~>cellView transform)
        )
        t
      )
    )
    

    Andrew

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • Aurel B
    Aurel B 22 days ago in reply to Andrew Beckett

    To be honest, I also had a more complicated solution but the forum did not let me post until I removed the `;unless ;Foreach obj` comment on the fourth line starting from the end...

    (No idea why but it seems ";Foreach" in lowercase is not allowed on the forum...)

    It does not cover the children issues, but it checks the ruler orientation to align vertically or horizontally.

    (defun cst_align_to_ruler
           ( @key  ( objects (geGetSelectedSet) )
             @rest _
             )
      "Align all OBJECTS on ruler center.
    Exactly one ruler has to be selected.
    If ruler is vertical, objects are aligned on its y coordinate.
    Otherwise, objects aare aligned to its y coordinate."
      ;; Fetch ruler
      (letseq ( ( rulers (setof obj objects (equal "ruler" obj->objType)) )
                ( ruler  (or (car rulers) (error "No ruler is selected")) )
                )
        (assert (not (cdr rulers)) "More than one ruler is selected")
        (assert (equal 2 ruler->nPoints) "Ruler has more than two points" )
        ;; Deduce ruler direction
        (destructuringBind ( ( ruler_x0 ruler_y0 ) ( ruler_x1 ruler_y1 ) ) ruler->points
          (let ( ( direction (cond
                               ( (nearlyEqual ruler_x0 ruler_x1) 'vertical  )
                               ( (nearlyEqual ruler_y0 ruler_y1) 'horizontal)
                               ( t (error "Unable to determine ruler direction from points: %N" ruler->points))
                               ) )
                 )
            (destructuringBind ( ruler_x ruler_y ) (centerBox ruler->points)
              ;; Browse all objects except rulers (other object types could be filtered here...)
              (foreach obj objects
                (unless (member obj->objType '( "ruler" ))
                  (destructuringBind ( obj_x obj_y ) (centerBox obj->bBox)
                    (caseq direction
                      ( vertical   (dbMoveFig obj obj->cellView (list ruler_x-obj_x:0 "R0" 1)) )
                      ( horizontal (dbMoveFig obj obj->cellView (list 0:ruler_y-obj_y "R0" 1)) )
                      ( t          (error "Unsupported direction (should never happen...)")    )
                      ));caseq ;dbind
                  ))
              );dbind
            ));let ;dbind
        ));letseq ;fun
    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • Andrew Beckett
    Andrew Beckett 22 days ago in reply to Aurel B
    Aurel B said:
    (No idea why but it seems ";Foreach" in lowercase is not allowed on the forum...)

    There are a few little oddities like this. There's one where the function that begins with sub and ends with string also fails - I've ended up changing code to use strncmp instead to get around this. It is what it is!

    Anyway, now the original poster has three different implementations. Hopefully one of them meets the goal or can be morphed into something that does! The original poster's code outline looks a bit as if it was generated by an LLM that didn't quite know what it was doing...

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • yogeshjaiswalCAD
    yogeshjaiswalCAD 22 days ago in reply to Aurel B

    Greetings Aurel,

    It means a lot when you take time from your busy schedule to reply to such answers; no one can imagine :)

    I have succeeded in this quest with your help ...  The code is functioning as expected  Slight smile

    Once again thanks for warm gesture

    Have a pleasant day!

    Cheers & regards,

    Yogesh Jaiswal 

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • yogeshjaiswalCAD
    yogeshjaiswalCAD 22 days ago in reply to Andrew Beckett

    Greetings Andrew,

    It means a lot when you take time from your busy schedule to reply to such answers; no one can imagine :)

    I have succeeded in this quest with your help ...  The code is functioning as expected  Slight smile

    Once again thanks for warm gesture

    Have a pleasant day!

    Cheers & regards,

    Yogesh Jaiswal 

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information