Jump to content

XREF layer


Alan_KD

Recommended Posts

Hello everyone,

 

I have been developing some routines for the pas 6 months, so my knowledge is not very high. Normally I manage to find answers online, thanks to all of you who share their knowledge, it's so helpful.

 

I am writing a routine which would:

 

Compare the XREF name on the drawing and the XREF 'real' file name and match them (on the drawing) if different.

After the code checks if the XREF name matches a specific formatting and if it does creates a layer based on it (if the layer does not already exist).

The final step is to change the XREF layer to that one, and here is where I am getting an error. I tried with different ways to do this and always got an error.

 

I guess I could try to get this done without using vl code but this is really puzzling me and I would like to know why is actually not working, I dont see where the code could have gone wrong.

 

The example names of my XREFs: which are used to compare with the wcmatch "*_*_*_*"

 

XREF_TGLMTE_PRO_INTER_BASSINS_01

XREF_TGLMTE_PRO_INTER_RESEAUX_HS_2025_01

XREF_TGLMTE_PRO_TRC_V5_IND_D

 

 

I used different lines of code to try to achieve this, as you can see on my commented lines on the code. 

I am currently using a (vlax-put-property it2 'layer strcalq) inside a vlax-for getting the following error:

 

Quote

Analyse rétrospective:
[0.57] (VL-BT)
[1.53] (ABD:ERROR "Le serveur ActiveX a renvoyé l'erreur: nom inconnu: LAYER")
[2.48] (_call-err-hook #<SUBR @0000029632c73c78 ABD:ERROR> "Le serveur ActiveX a renvoyé l'erreur: nom inconnu: LAYER")
[3.42] (sys-error "Le serveur ActiveX a renvoyé l'erreur: nom inconnu: LAYER")
:ERROR-BREAK.37 nil
[4.34] (intelligent-invoke #<VLA-OBJECT IAcadBlock 0000029ec1c94378> LAYER 4 "SF-XREF_BATI_FOSSE")
[5.26] (vlax-put-property #<VLA-OBJECT IAcadBlock 0000029ec1c94378> LAYER "SF-XREF_BATI_FOSSE")
[6.19] (C:XRCALQUE)
[7.15] (#<SUBR @0000029632c73f20 -rts_top->)
[8.12] (#<SUBR @000002962b338700 veval-str-body> "(C:XRCALQUE)" T #<FILE internal>)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 0)

 

 

(defun c:xrcalque (/ AcadObj AcadAct LyAct it2 xrobjectname strcalq)

(vl-load-com)
(setq *error* ABD:Error)

(setq AcadObj (vlax-get-Acad-Object))
(setq AcadAct (vla-get-ActiveDocument AcadObj))

(setq LyAct (vla-get-layers AcadAct)) ;get layers from Active document

(xrn AcadObj AcadAct); runs the subroutine to change XREF name on drawing to match XREF file name

(vlax-for it2 (vla-get-blocks AcadAct)
    (setq ind1 3)
    (setq ind2 0)
    (setq ind3 0)
    (if (= (vla-get-isxref it2) :vlax-true)
        (progn
            (setq xrobjectname (vl-filename-base (vla-get-name it2)))
            (if (wcmatch xrobjectname "*_*_*_*");
                (progn
                        (repeat ind1
                            (setq ind3 (+ ind2 1))
                            (setq ind2 (vl-string-position (ascii "_") xrobjectname ind3));gets firs position of "_" character
                        )
                    (print xrobjectname)
                    (setq ind2 (+ ind2 2))
                    (print ind2) ; ind2 is the position of the ind1 "_" element (3rd) to count from there to have the layer name
                    (setq ind4 (vl-string-position (ascii "_") xrobjectname nil T)); last "_" position
                    (setq ind5 (vl-string-position (ascii "-") xrobjectname nil T)); last "-" position
                    (if (> ind4 ind5)(setq indlst ind4)(setq indlst ind5)) ;check which one is bigger
                    (setq indlst (+ 1 indlst))
                        (setq strcalq (strcat "SF-XREF_"(substr xrobjectname ind2 (- indlst ind2))))
                        ;Create layer with string from ind2 position to ind4 or ind5 position (strcalq)
                        (print strcalq)
                    (if (not (tblsearch "LAYER" strcalq));checks non existance of layer
                        (progn
                            (vla-add LyAct strcalq)
                            (print "Layer has been created")
                        )
                        (progn


                             ;(vla-put-layer it2 "0")
                            ; (print "this is a test4")
                            (print "layer exists")
                            ;if layer exists put object on layer
                        )
                    );if
                    (print strcalq)
                    ;(vla-put-layer it2 "0")
                    ;(vla-put-layer xrobjectname strcalq)
                    ;(vla-put-layer (vla-get-name it2) strcalq)
                    ;(vlax-put it2 'Layer "0")
                    ;(vlax-put (vlax-ename->vla-object (vla-get-name it2)) 'Layer "0")
                    (vlax-put-property it2 'layer strcalq);############ ERROR###############

                );progn
                (print "wcmatch xref name not matching")
            );if
        );progn
    );if
    ;(vlax-put (vlax-ename->vla-object xrtemp) 'Layer strcalq)
);vlax for

(print "highly recommended to purge layers") ;add code to purge automatically the layers?

(princ)

);defun


;;;=======================================  Error function  ++++++++++++++++++++++++++++++++++++++++;;;
(defun ABD:Error (st)
    (if (not (member st (list "Fonction annulée" "quitter / sortir abandon")))
        (vl-bt)
    );if
    ;(princ "Merci d'envoyer vos commentaires ou report d'erreurs à ")
    (princ);clean exit ?  
);defun error

;;;=======================================  function xrn  +++++++++++++++++++++++++++++++++++++++++++;;;

(defun xrn (AcadObj AcadAct / item xrobjectnamexrn xrfilenamexrn)

(vlax-for item (vla-get-blocks AcadAct)
    (if (= (vla-get-isxref item) :vlax-true)
        (progn
            (setq xrobjectnamexrn (vl-filename-base (vla-get-name item)))
            (setq xrfilenamexrn (vl-filename-base (vla-get-path item)))

            (if (/= xrobjectnamexrn xrfilenamexrn)
                (progn
                    (vla-put-name item xrfilenamexrn)
                    (vla-reload item)
                )
            )
        )
    )
)

);defun xrn

 

If someone could explain why this is not working, and please share a way to achieve my goal would be awesome!

 

Thank you in advance,

 

Alan

Edited by Alan_KD
Link to comment
Share on other sites

In your code it2 is a block definition. A block definition object does not have a layer property.

So:

(vlax-put-property it2 'layer strcalq)

Will fail.

 

You need to change the layer of the block references.

Link to comment
Share on other sites

11 minutes ago, Roy_043 said:

In your code it2 is a block definition. A block definition object does not have a layer property.

So:


(vlax-put-property it2 'layer strcalq)

Will fail.

 

You need to change the layer of the block references.

 

Oh yes.

In that case, this works

 

  (setq xrf (ssget "_X" (list (cons 0 "INSERT") (cons 2 xrobjectname) )))
  (vlax-put-property (vlax-ename->vla-object (ssname xrf 0)) 'layer strcalq); 

Edited by Emmanuel Delay
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...